use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class TestBodyProcessorCreator method testCreateNormal.
@Test
public void testCreateNormal() {
ParamValueProcessorCreator creator = ParamValueProcessorCreatorManager.INSTANCE.findValue(BodyProcessorCreator.PARAMTYPE);
BodyParameter param = new BodyParameter();
ParamValueProcessor processor = creator.create(param, String.class);
Assert.assertEquals(BodyProcessor.class, processor.getClass());
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class TestBodyProcessorCreator method testCreateRawJson.
@Test
public void testCreateRawJson() {
ParamValueProcessorCreator creator = ParamValueProcessorCreatorManager.INSTANCE.findValue(BodyProcessorCreator.PARAMTYPE);
BodyParameter param = new BodyParameter();
param.setVendorExtension(SwaggerConst.EXT_RAW_JSON_TYPE, true);
ParamValueProcessor processor = creator.create(param, String.class);
Assert.assertEquals(RawJsonBodyProcessor.class, processor.getClass());
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class TestApiImplicitParams method testBody.
@Test
public void testBody() {
Swagger swagger = SwaggerGenerator.generate(ApiImplicitParamsAnnotation.class);
Path path = swagger.getPaths().get("/testBody");
Operation operation = path.getOperations().get(0);
BodyParameter parameter = (BodyParameter) operation.getParameters().get(0);
Assert.assertEquals("body", parameter.getName());
Assert.assertEquals("User", ((RefModel) parameter.getSchema()).getSimpleRef());
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class RestOperationMeta method correctFormBodyType.
/**
* EdgeService cannot recognize the map type form body whose value type is String,
* so there should be this additional setting.
* @param parameter the swagger information of the parameter
* @param type the resolved param type
* @return the corrected param type
*/
private Type correctFormBodyType(Parameter parameter, Type type) {
if (null != type || !(parameter instanceof BodyParameter)) {
return type;
}
final BodyParameter bodyParameter = (BodyParameter) parameter;
if (!(bodyParameter.getSchema() instanceof ModelImpl)) {
return type;
}
final Property additionalProperties = ((ModelImpl) bodyParameter.getSchema()).getAdditionalProperties();
if (additionalProperties instanceof StringProperty) {
type = RestObjectMapperFactory.getRestObjectMapper().getTypeFactory().constructMapType(Map.class, String.class, String.class);
}
return type;
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method fillBodyParameter.
protected void fillBodyParameter(Swagger swagger, Parameter parameter, Type type, List<Annotation> annotations) {
// so strange, for bodyParameter, swagger return a new instance
// that will cause lost some information
// so we must merge them
BodyParameter newBodyParameter = (BodyParameter) io.swagger.util.ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations);
// swagger missed enum data, fix it
ModelImpl model = SwaggerUtils.getModelImpl(swagger, newBodyParameter);
if (model != null) {
Property property = ModelConverters.getInstance().readAsProperty(type);
if (property instanceof StringProperty) {
model.setEnum(((StringProperty) property).getEnum());
}
}
// swagger 2.0 do not support NotBlank and NotEmpty annotations, fix it
if (((JavaType) type).getBindings().getTypeParameters().isEmpty()) {
convertAnnotationProperty(((JavaType) type).getRawClass());
} else {
((JavaType) type).getBindings().getTypeParameters().stream().forEach(javaType -> convertAnnotationProperty(javaType.getRawClass()));
}
mergeBodyParameter((BodyParameter) parameter, newBodyParameter);
}
Aggregations