use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class ServletReaderExtension method readImplicitParam.
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) {
final Parameter p = ParameterFactory.createParam(param.paramType());
if (p == null) {
return null;
}
final Type type = ReflectionUtils.typeFromString(param.dataType());
return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type, Collections.<Annotation>singletonList(param));
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class OperationTest method testParameter.
@Test
public void testParameter() {
// given
Parameter parameter = Mockito.mock(Parameter.class);
operation.setParameters(null);
// when
operation.parameter(parameter);
assertTrue(operation.getParameters().contains(parameter), "The newly added parameter must be contained in the parameters list");
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SwaggerTest method testParameter.
@Test
public void testParameter() {
// given
Parameter parameter = Mockito.mock(Parameter.class);
// when
swagger.setParameters(null);
String key = "key";
// then
assertNull(swagger.getParameter(key), "Cannot retrieve a key without adding it first");
// when
swagger.parameter(key, parameter);
// then
assertEquals(swagger.getParameters().get(key), parameter, "Must be able to retrieve the added key");
assertEquals(swagger.getParameter(key), parameter, "Must be able to retrieave the added key");
}
use of io.swagger.models.parameters.Parameter 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.models.parameters.Parameter 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;
}
}
Aggregations