use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project cxf by apache.
the class JaxRs2Extension method extractParameters.
@SuppressWarnings("deprecation")
@Override
public List<Parameter> extractParameters(final List<Annotation> annotations, final Type type, final Set<Type> typesToSkip, final Iterator<SwaggerExtension> chain) {
if (shouldIgnoreType(type, typesToSkip)) {
return new ArrayList<>();
}
List<Parameter> parameters = new ArrayList<>();
for (Annotation annotation : annotations) {
if (annotation instanceof MatrixParam) {
MatrixParam param = (MatrixParam) annotation;
MatrixParameter mp = new MatrixParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
mp.setProperty(schema);
}
applyBeanValidatorAnnotations(mp, annotations);
parameters.add(mp);
} else if (annotation instanceof BeanParam) {
// Use Jackson's logic for processing Beans
final BeanDescription beanDesc = mapper.getSerializationConfig().introspect(constructType(type));
final List<BeanPropertyDefinition> properties = beanDesc.findProperties();
for (final BeanPropertyDefinition propDef : properties) {
final AnnotatedField field = propDef.getField();
final AnnotatedMethod setter = propDef.getSetter();
final List<Annotation> paramAnnotations = new ArrayList<>();
final Iterator<SwaggerExtension> extensions = SwaggerExtensions.chain();
Type paramType = null;
// Gather the field's details
if (field != null) {
paramType = field.getAnnotated().getGenericType();
for (final Annotation fieldAnnotation : field.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the setter's details but only the ones we need
if (setter != null) {
// Do not set the param class/type from the setter if the values are already identified
if (paramType == null && setter.getMember().getGenericParameterTypes() != null) {
paramType = setter.getMember().getGenericParameterTypes()[0];
}
for (final Annotation fieldAnnotation : setter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Re-process all Bean fields and let the default swagger-jaxrs processor do its thing
List<Parameter> extracted = extensions.next().extractParameters(paramAnnotations, paramType, typesToSkip, extensions);
// since downstream processors won't know how to introspect @BeanParam, process here
for (Parameter param : extracted) {
if (ParameterProcessor.applyAnnotations(null, param, paramType, paramAnnotations) != null) {
applyBeanValidatorAnnotations(param, paramAnnotations);
parameters.add(param);
}
}
}
}
}
// Only call down to the other items in the chain if no parameters were produced
if (parameters.isEmpty()) {
parameters = super.extractParameters(annotations, type, typesToSkip, chain);
}
return parameters;
}
Aggregations