use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project incubator-servicecomb-java-chassis by apache.
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 incubator-servicecomb-java-chassis by apache.
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);
}
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);
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method scanMethodParameters.
protected void scanMethodParameters() {
initParameterGenerators();
Set<String> names = new HashSet<>();
for (ParameterGenerator parameterGenerator : parameterGenerators) {
scanMethodParameter(parameterGenerator);
if (!names.add(parameterGenerator.getParameterName())) {
throw new IllegalStateException(String.format("not support duplicated parameter, name=%s.", parameterGenerator.getParameterName()));
}
swaggerOperation.addParameter(parameterGenerator.getGeneratedParameter());
}
}
use of org.apache.servicecomb.swagger.generator.ParameterGenerator in project incubator-servicecomb-java-chassis by apache.
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);
}
}
Aggregations