use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class PojoOperationGenerator method wrapParametersToBody.
private void wrapParametersToBody(List<ParameterGenerator> bodyFields) {
String simpleRef = MethodUtils.findSwaggerMethodName(method) + "Body";
bodyModel = new ModelImpl();
bodyModel.setType(ModelImpl.OBJECT);
for (ParameterGenerator parameterGenerator : bodyFields) {
// to collect all information by swagger mechanism
// must have a parameter type
// but all these parameters will be wrap to be one body parameter, their parameter type must be null
// so we first set to be BODY, after collected, set back to be null
parameterGenerator.setHttpParameterType(HttpParameterType.BODY);
scanMethodParameter(parameterGenerator);
Property property = ModelConverters.getInstance().readAsProperty(parameterGenerator.getGenericType());
property.setDescription(parameterGenerator.getGeneratedParameter().getDescription());
bodyModel.addProperty(parameterGenerator.getParameterName(), property);
parameterGenerator.setHttpParameterType(null);
}
swagger.addDefinition(simpleRef, bodyModel);
SwaggerGeneratorFeature feature = swaggerGenerator.getSwaggerGeneratorFeature();
// if not care for this, then can just delete all logic about EXT_JAVA_CLASS/EXT_JAVA_INTF
if (feature.isExtJavaClassInVendor() && bodyFields.size() > 1 && StringUtils.isNotEmpty(feature.getPackageName())) {
bodyModel.getVendorExtensions().put(SwaggerConst.EXT_JAVA_CLASS, feature.getPackageName() + "." + simpleRef);
}
RefModel refModel = new RefModel();
refModel.setReference("#/definitions/" + simpleRef);
bodyParameter = new BodyParameter();
bodyParameter.name(simpleRef);
bodyParameter.setSchema(refModel);
bodyParameter.setName(parameterGenerators.size() == 1 ? parameterGenerators.get(0).getParameterName() : simpleRef);
List<ParameterGenerator> newParameterGenerators = new ArrayList<>();
newParameterGenerators.add(new ParameterGenerator(bodyParameter.getName(), Collections.emptyList(), null, HttpParameterType.BODY, bodyParameter));
parameterGenerators.stream().filter(p -> p.getHttpParameterType() != null).forEach(p -> newParameterGenerators.add(p));
parameterGenerators = newParameterGenerators;
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method extractAggregatedParameterGenerators.
protected void extractAggregatedParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap, java.lang.reflect.Parameter methodParameter) {
JavaType javaType = TypeFactory.defaultInstance().constructType(methodParameter.getParameterizedType());
BeanDescription beanDescription = Json.mapper().getSerializationConfig().introspect(javaType);
for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
if (!propertyDefinition.couldSerialize()) {
continue;
}
Annotation[] annotations = collectAnnotations(propertyDefinition);
ParameterGenerator propertyParameterGenerator = new ParameterGenerator(method, methodAnnotationMap, propertyDefinition.getName(), annotations, propertyDefinition.getPrimaryType());
parameterGenerators.add(propertyParameterGenerator);
}
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method initMethodParameterGenerators.
protected void initMethodParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap) {
for (java.lang.reflect.Parameter methodParameter : method.getParameters()) {
Type genericType = TypeToken.of(clazz).resolveType(methodParameter.getParameterizedType()).getType();
ParameterGenerator parameterGenerator = new ParameterGenerator(method, methodAnnotationMap, methodParameter, genericType);
validateParameter(parameterGenerator.getGenericType());
if (isContextParameter(parameterGenerator.getGenericType())) {
continue;
}
// springmvc: is query, and is bean type
if (isAggregatedParameter(parameterGenerator, methodParameter)) {
extractAggregatedParameterGenerators(methodAnnotationMap, methodParameter);
continue;
}
parameterGenerators.add(parameterGenerator);
}
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method initRemainMethodAnnotationsParameterGenerators.
protected void initRemainMethodAnnotationsParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap) {
for (Entry<String, List<Annotation>> entry : methodAnnotationMap.entrySet()) {
ParameterGenerator parameterGenerator = new ParameterGenerator(entry.getKey(), entry.getValue());
parameterGenerators.add(parameterGenerator);
}
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class PojoOperationGenerator method tryWrapParametersToBody.
private void tryWrapParametersToBody() {
List<ParameterGenerator> bodyFields = parameterGenerators.stream().filter(pg -> pg.getHttpParameterType() == null).collect(Collectors.toList());
if (bodyFields.isEmpty()) {
return;
}
if (bodyFields.size() == 1 && SwaggerUtils.isBean(bodyFields.get(0).getGenericType())) {
ParameterGenerator parameterGenerator = bodyFields.get(0);
parameterGenerator.setHttpParameterType(HttpParameterType.BODY);
return;
}
// wrap parameters to body
wrapParametersToBody(bodyFields);
}
Aggregations