io.swagger.models.parameters.FormParameter Java Examples

The following examples show how to use io.swagger.models.parameters.FormParameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected Parameter createParameter(HttpParameterType httpParameterType) {
  switch (httpParameterType) {
    case PATH:
      return new PathParameter();
    case QUERY:
      return new QueryParameter();
    case HEADER:
      return new HeaderParameter();
    case FORM:
      return new FormParameter();
    case COOKIE:
      return new CookieParameter();
    case BODY:
      return new BodyParameter();
    default:
      throw new IllegalStateException("not support httpParameterType " + httpParameterType);
  }
}
 
Example #2
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static boolean isFileParameter(Parameter parameter) {
  if (!(parameter instanceof FormParameter)) {
    return false;
  }

  FormParameter formParameter = (FormParameter) parameter;
  if (FileProperty.isType(formParameter.getType(), formParameter.getFormat())) {
    return true;
  }

  Property property = formParameter.getItems();
  if (!ArrayProperty.isType(formParameter.getType()) || property == null) {
    return false;
  }

  return FileProperty.isType(property.getType(), property.getFormat());
}
 
Example #3
Source File: FormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private boolean isPart(Parameter parameter) {
  // no need to check Part[][] and so on
  FormParameter formParameter = (FormParameter) parameter;
  if ("array".equals(formParameter.getType())) {
    Property items = formParameter.getItems();
    return new FileProperty().getType().equals(items.getType());
  }
  return new FileProperty().getType().equals(formParameter.getType());
}
 
Example #4
Source File: SwaggerReader.java    From netty-rest with Apache License 2.0 5 votes vote down vote up
public List<Parameter> extractParameters(Annotation[] annotations, Type type)
{
    String defaultValue = null;

    List<Parameter> parameters = new ArrayList<>();
    Parameter parameter = null;

    for (Annotation annotation : annotations) {
        if (annotation instanceof ApiParam) {
            FormParameter qp = new FormParameter()
                    .name(((ApiParam) annotation).value());
            qp.setDefaultValue(defaultValue);
            Property schema = modelConverters.readAsProperty(type);
            if (schema != null) {
                qp.setProperty(schema);
                if (schema instanceof ArrayProperty) {
                    qp.setItems(((ArrayProperty) schema).getItems());
                }
            }
            parameter = qp;
        }
    }
    if (parameter != null) {
        parameters.add(parameter);
    }

    return parameters;
}
 
Example #5
Source File: ComponentUploadParameterContributor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static Collection<FormParameter> transformUploadDefinitions(final Collection<UploadDefinition> uploadDefinitions) {
  Collection<FormParameter> parameters = new ArrayList<>();

  for (UploadDefinition uploadDefinition : uploadDefinitions) {
    uploadDefinition.getComponentFields().forEach(uploadFieldDefinition -> parameters.add(new FormParameter()
        .name(uploadDefinition.getFormat() + "." + uploadFieldDefinition.getName())
        .type(uploadFieldDefinition.getType().name().toLowerCase())
        .description(uploadDefinition.getFormat() + " " + uploadFieldDefinition.getDisplayName())));

    for (int i = 1; i <= (uploadDefinition.isMultipleUpload() ? 3 : 1); i++) {
      String assetIndex = uploadDefinition.isMultipleUpload() ? Integer.toString(i) : "";
      String assetName = uploadDefinition.getFormat() + ".asset" + assetIndex;
      String assetDisplayName = uploadDefinition.getFormat() + " Asset " + assetIndex;

      parameters.add(new FormParameter()
          .name(assetName)
          .type("file")
          .description(assetDisplayName));

      uploadDefinition.getAssetFields().forEach(uploadFieldDefinition -> parameters.add(new FormParameter()
          .name(assetName + "." + uploadFieldDefinition.getName())
          .type(uploadFieldDefinition.getType().name().toLowerCase())
          .description(assetDisplayName + " " + uploadFieldDefinition.getDisplayName())));
    }
  }

  return parameters;
}
 
Example #6
Source File: SwaggerWorkflowReader.java    From mdw with Apache License 2.0 5 votes vote down vote up
private io.swagger.models.parameters.Parameter createParam(ParameterType paramType) {
    if (paramType == ParameterType.Path)
        return new PathParameter();
    else if (paramType == ParameterType.Query)
        return new QueryParameter();
    else if (paramType == ParameterType.Form)
        return new FormParameter();
    else if (paramType == ParameterType.Header)
        return new HeaderParameter();
    else if (paramType == ParameterType.Body)
        return new BodyParameter();
    return null;
}
 
Example #7
Source File: ResourceReaderExtension.java    From mdw with Apache License 2.0 5 votes vote down vote up
private Parameter createParam(String paramType) {
    if ("path".equals(paramType))
        return new PathParameter();
    else if ("query".equals(paramType))
        return new QueryParameter();
    else if ("form".equals(paramType))
        return new FormParameter();
    else if ("formData".equals(paramType))
        return new FormParameter();
    else if ("header".equals(paramType))
        return new HeaderParameter();
    else if ("body".equals(paramType))
        return new BodyParameter();
    return null;
}
 
Example #8
Source File: FormParameterExtractor.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
@Override
public Object extract(String name, Parameter parameter, RoutingContext context) {
    FormParameter formParam = (FormParameter) parameter;
    if ("file".equals(formParam.getType())) {
        for (FileUpload file : context.fileUploads()) {
            if (file.name().equals(name)) {
                return file.uploadedFileName();
            }
        }
        if(formParam.getRequired())
            throw new IllegalArgumentException("Missing required parameter: " + name);
        return null;
    } else 
        return this.extract(name, parameter, context.request().formAttributes());
}
 
Example #9
Source File: TestFormProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private FormProcessor createProcessor(String name, Type type, String defaultValue, boolean required) {
  JavaType javaType = TypeFactory.defaultInstance().constructType(type);

  FormParameter formParameter = new FormParameter();
  formParameter.name(name)
      .required(required)
      .setDefaultValue(defaultValue);

  if (javaType.isContainerType()) {
    formParameter.type(ArrayProperty.TYPE);
  }
  return new FormProcessor(formParameter, javaType);
}
 
Example #10
Source File: TestFormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() {
  ParamValueProcessorCreator creator =
      ParamValueProcessorCreatorManager.INSTANCE.findValue(FormProcessorCreator.PARAMTYPE);
  FormParameter p = new FormParameter();
  p.setName("p1");

  ParamValueProcessor processor = creator.create(p, String.class);

  Assert.assertEquals(FormProcessor.class, processor.getClass());
}
 
Example #11
Source File: FormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
PartProcessor(FormParameter formParameter, Type genericParamType) {
  super(formParameter.getName(), null, formParameter.getDefaultValue(), formParameter.getRequired());

  this.genericParamType = genericParamType;
  this.repeatedType = ArrayProperty.isType(formParameter.getType());
  initConverter(genericParamType);
}
 
Example #12
Source File: AbstractJavaCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    if (swagger == null || swagger.getPaths() == null){
        return;
    }
    for (String pathname : swagger.getPaths().keySet()) {
        Path path = swagger.getPath(pathname);
        if (path.getOperations() == null){
            continue;
        }
        for (Operation operation : path.getOperations()) {
            boolean hasFormParameters = false;
            boolean hasBodyParameters = false;
            for (Parameter parameter : operation.getParameters()) {
                if (parameter instanceof FormParameter) {
                    hasFormParameters = true;
                }
                if (parameter instanceof BodyParameter) {
                    hasBodyParameters = true;
                }
            }
            if (hasBodyParameters || hasFormParameters){
                String defaultContentType = hasFormParameters ? "application/x-www-form-urlencoded" : "application/json";
                String contentType =  operation.getConsumes() == null || operation.getConsumes().isEmpty() ? defaultContentType : operation.getConsumes().get(0);
                operation.setVendorExtension("x-contentType", contentType);
            }
            String accepts = getAccept(operation);
            operation.setVendorExtension("x-accepts", accepts);
        }
    }
}
 
Example #13
Source File: FormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public ParamValueProcessor create(Parameter parameter, Type genericParamType) {
  JavaType targetType =
      genericParamType == null ? null : TypeFactory.defaultInstance().constructType(genericParamType);

  if (isPart(parameter)) {
    return new PartProcessor((FormParameter) parameter, genericParamType);
  }
  return new FormProcessor((FormParameter) parameter, targetType);
}
 
Example #14
Source File: DubboReaderExtension.java    From swagger-dubbo with Apache License 2.0 5 votes vote down vote up
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) {
	PrimitiveType fromType = PrimitiveType.fromName(param.paramType());
	final Parameter p = null == fromType ? new FormParameter() : new QueryParameter();
	final Type type = ReflectionUtils.typeFromString(param.dataType());
	return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type,
			Collections.<Annotation> singletonList(param));
}
 
Example #15
Source File: RpcReaderExtension.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) {
    PrimitiveType fromType = PrimitiveType.fromName(param.paramType());
    final Parameter p = null == fromType ? new FormParameter() : new QueryParameter();
    final Type type = ReflectionUtils.typeFromString(param.dataType());
    return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type,
        Collections.<Annotation> singletonList(param));
}
 
Example #16
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param operation
 * @return
 */
private String getMethodParameters(Operation operation) {
	String methodParameter = "";
	List<Parameter> parameters = operation.getParameters();

	for (Parameter parameter : parameters) {
		if (StringUtils.isNotEmpty(methodParameter)) {
			methodParameter = new StringBuilder().append(methodParameter).append(",").toString();
		}

		if (parameter instanceof PathParameter) {
			methodParameter = new StringBuilder().append(methodParameter)
					.append(toTitleCase(((PathParameter) parameter).getType())).append(" ")
					.append(((PathParameter) parameter).getName()).toString();
		} else if (parameter instanceof QueryParameter) {
			Property queryParameterProperty = ((QueryParameter) parameter).getItems();

			if (queryParameterProperty instanceof RefProperty) {
				methodParameter = new StringBuilder().append(methodParameter)
						.append(toTitleCase(((RefProperty) queryParameterProperty).getSimpleRef())).append("[] ")
						.append(((BodyParameter) parameter).getName()).toString();
			} else if (queryParameterProperty instanceof StringProperty) {
				methodParameter = new StringBuilder().append(methodParameter)
						.append(toTitleCase(((StringProperty) queryParameterProperty).getType())).append("[] ")
						.append(((QueryParameter) parameter).getName()).toString();
			} else {
				methodParameter = new StringBuilder().append(methodParameter)
						.append(toTitleCase(((QueryParameter) parameter).getType())).append(" ")
						.append(((QueryParameter) parameter).getName()).toString();
			}
		} else if (parameter instanceof BodyParameter) {
			Model bodyParameter = ((BodyParameter) parameter).getSchema();

			if (bodyParameter instanceof RefModel) {
				methodParameter = new StringBuilder().append(methodParameter)
						.append(toTitleCase(((RefModel) bodyParameter).getSimpleRef())).append(" ")
						.append(((BodyParameter) parameter).getName()).toString();
			} else if (bodyParameter instanceof ArrayModel) {
				Property propertyObject = ((ArrayModel) bodyParameter).getItems();

				if (propertyObject instanceof RefProperty) {
					methodParameter = new StringBuilder().append(methodParameter)
							.append(toTitleCase(((RefProperty) propertyObject).getSimpleRef())).append("[] ")
							.append(((BodyParameter) parameter).getName()).toString();
				}
			}
		} else if (parameter instanceof FormParameter) {
			methodParameter = new StringBuilder().append(methodParameter)
					.append(toTitleCase(((FormParameter) parameter).getType())).append(" ")
					.append(((FormParameter) parameter).getName()).toString();
		}
	}

	return methodParameter;
}
 
Example #17
Source File: FormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public FormProcessor(FormParameter formParameter, JavaType targetType) {
  super(formParameter.getName(), targetType, formParameter.getDefaultValue(), formParameter.getRequired());

  this.repeatedType = ArrayProperty.isType(formParameter.getType());
}
 
Example #18
Source File: PartArrayProcessor.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public void fillParameter(Swagger swagger, Operation operation, FormParameter parameter, Type type,
    Annotation annotation) {
  Property property = new ArrayProperty(new FileProperty());
  parameter.setProperty(property);
}
 
Example #19
Source File: PartProcessor.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public void fillParameter(Swagger swagger, Operation operation, FormParameter parameter, Type type,
    Annotation annotation) {
  parameter.setType(new FileProperty().getType());
}