use of io.swagger.jaxrs.ext.SwaggerExtension in project swagger-core by swagger-api.
the class DefaultParameterExtension method handleAdditionalAnnotation.
/**
* Adds additional annotation processing support
*
* @param parameters
* @param annotation
* @param type
* @param typesToSkip
*/
private void handleAdditionalAnnotation(List<Parameter> parameters, Annotation annotation, final Type type, Set<Type> typesToSkip) {
if (CLASS_BEAN_PARAM != null && CLASS_BEAN_PARAM.isAssignableFrom(annotation.getClass())) {
// 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 AnnotatedMethod getter = propDef.getGetter();
final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
final Iterator<SwaggerExtension> extensions = SwaggerExtensions.chain();
Type paramType = null;
// Gather the field's details
if (field != null) {
paramType = field.getRawType();
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) {
paramType = setter.getRawParameterTypes() != null ? setter.getRawParameterTypes()[0] : null;
}
for (final Annotation fieldAnnotation : setter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the getter's details but only the ones we need
if (getter != null) {
// Do not set the param class/type from the getter if the values are already identified
if (paramType == null) {
paramType = getter.getRawReturnType();
}
for (final Annotation fieldAnnotation : getter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
if (paramType == null) {
continue;
}
// Re-process all Bean fields and let the default swagger-jaxrs/swagger-jersey-jaxrs processors do their 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) {
parameters.add(param);
}
}
}
}
}
use of io.swagger.jaxrs.ext.SwaggerExtension in project swagger-core by swagger-api.
the class Reader method getParameters.
private List<Parameter> getParameters(Type type, List<Annotation> annotations) {
final Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
if (!chain.hasNext()) {
return Collections.emptyList();
}
LOGGER.debug("getParameters for {}", type);
Set<Type> typesToSkip = new HashSet<Type>();
final SwaggerExtension extension = chain.next();
LOGGER.debug("trying extension {}", extension);
final List<Parameter> parameters = extension.extractParameters(annotations, type, typesToSkip, chain);
if (!parameters.isEmpty()) {
final List<Parameter> processed = new ArrayList<Parameter>(parameters.size());
for (Parameter parameter : parameters) {
if (ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations) != null) {
processed.add(parameter);
}
}
return processed;
} else {
LOGGER.debug("no parameter found, looking at body params");
final List<Parameter> body = new ArrayList<Parameter>();
if (!typesToSkip.contains(type)) {
Parameter param = ParameterProcessor.applyAnnotations(swagger, null, type, annotations);
if (param != null) {
body.add(param);
}
}
return body;
}
}
use of io.swagger.jaxrs.ext.SwaggerExtension in project swagger-core by swagger-api.
the class Reader method processOperationDecorator.
private void processOperationDecorator(Operation operation, Method method) {
final Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
if (chain.hasNext()) {
SwaggerExtension extension = chain.next();
LOGGER.debug("trying to decorate operation: {}", extension);
extension.decorateOperation(operation, method, chain);
}
}
Aggregations