use of io.swagger.models.parameters.FormParameter in project swagger-core by swagger-api.
the class Reader method readImplicitParam.
protected Parameter readImplicitParam(ApiImplicitParam param) {
final Parameter p;
if (param.paramType().equalsIgnoreCase("path")) {
p = new PathParameter();
} else if (param.paramType().equalsIgnoreCase("query")) {
p = new QueryParameter();
} else if (param.paramType().equalsIgnoreCase("form") || param.paramType().equalsIgnoreCase("formData")) {
p = new FormParameter();
} else if (param.paramType().equalsIgnoreCase("body")) {
p = null;
} else if (param.paramType().equalsIgnoreCase("header")) {
p = new HeaderParameter();
} else {
LOGGER.warn("Unknown implicit parameter type: [{}]", param.paramType());
return null;
}
final Type type = param.dataTypeClass() == Void.class ? ReflectionUtils.typeFromString(param.dataType()) : param.dataTypeClass();
return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type, Arrays.<Annotation>asList(param));
}
use of io.swagger.models.parameters.FormParameter in project swagger-core by swagger-api.
the class ReaderTest method scanImplicitParam.
@Test(description = "scan implicit params")
public void scanImplicitParam() {
Swagger swagger = getSwagger(ResourceWithImplicitParams.class);
List<Parameter> params = swagger.getPath("/testString").getPost().getParameters();
assertNotNull(params);
assertEquals(params.size(), 7);
assertEquals(params.get(0).getName(), "sort");
assertEquals(params.get(0).getIn(), "query");
PathParameter pathParam = (PathParameter) params.get(1);
assertEquals(pathParam.getName(), "type");
assertEquals(pathParam.getIn(), "path");
assertEquals(pathParam.getEnum().size(), 3);
assertEquals(pathParam.getType(), "string");
HeaderParameter headerParam = (HeaderParameter) params.get(2);
assertEquals(headerParam.getName(), "size");
assertEquals(headerParam.getIn(), "header");
assertEquals(headerParam.getMinimum(), new BigDecimal(1.0));
FormParameter formParam = (FormParameter) params.get(3);
assertEquals(formParam.getName(), "width");
assertEquals(formParam.getIn(), "formData");
assertEquals(formParam.getMaximum(), new BigDecimal(1.0));
assertEquals(params.get(4).getName(), "width");
assertEquals(params.get(4).getIn(), "formData");
QueryParameter queryParam = (QueryParameter) params.get(5);
assertEquals(queryParam.getName(), "height");
assertEquals(queryParam.getIn(), "query");
assertEquals(queryParam.getMinimum(), new BigDecimal(3.0));
assertEquals(queryParam.getMaximum(), new BigDecimal(4.0));
BodyParameter bodyParam = (BodyParameter) params.get(6);
assertEquals(bodyParam.getName(), "body");
assertEquals(bodyParam.getIn(), "body");
assertTrue(bodyParam.getRequired());
}
use of io.swagger.models.parameters.FormParameter in project swagger-core by swagger-api.
the class SwaggerJersey2JaxrsTest method returnProperFormDataParam.
@Test(description = "return the proper @FormDataParam Parameters based on the call to extractParameters")
public void returnProperFormDataParam() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("testFormDataParamRoute", InputStream.class, FormDataContentDisposition.class);
final List<Pair<Type, Annotation[]>> parameters = getParameters(method.getGenericParameterTypes(), method.getParameterAnnotations());
for (Pair<Type, Annotation[]> parameter : parameters) {
Type parameterType = parameter.first();
List<Parameter> swaggerParams = new SwaggerJersey2Jaxrs().extractParameters(Arrays.asList(parameter.second()), parameterType, new HashSet<Type>(), SwaggerExtensions.chain());
if (parameterType.equals(InputStream.class)) {
assertEquals(((FormParameter) swaggerParams.get(0)).getType(), "file");
} else {
assertEquals(swaggerParams.size(), 0);
}
}
}
Aggregations