use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method deserializeReadOnlyParameter.
@Test(description = "it should deserialize a read only parameter")
public void deserializeReadOnlyParameter() throws IOException {
final String json = "{" + " \"in\":\"path\"," + " \"required\":false," + " \"type\":\"string\"," + " \"readOnly\":\"true\"" + "}";
final Parameter p = m.readValue(json, Parameter.class);
assertTrue(p.isReadOnly());
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class ReaderUtils method collectConstructorParameters.
/**
* Collects constructor-level parameters from class.
*
* @param cls is a class for collecting
* @param swagger is the instance of the Swagger
* @return the collection of supported parameters
*/
public static List<Parameter> collectConstructorParameters(Class<?> cls, Swagger swagger) {
if (cls.isLocalClass() || (cls.isMemberClass() && !Modifier.isStatic(cls.getModifiers()))) {
return Collections.emptyList();
}
List<Parameter> selected = Collections.emptyList();
int maxParamsCount = 0;
for (Constructor<?> constructor : cls.getDeclaredConstructors()) {
if (!ReflectionUtils.isConstructorCompatible(constructor) && !ReflectionUtils.isInject(Arrays.asList(constructor.getDeclaredAnnotations()))) {
continue;
}
final Type[] genericParameterTypes = constructor.getGenericParameterTypes();
final Annotation[][] annotations = constructor.getParameterAnnotations();
int paramsCount = 0;
final List<Parameter> parameters = new ArrayList<Parameter>();
for (int i = 0; i < genericParameterTypes.length; i++) {
final List<Annotation> tmpAnnotations = Arrays.asList(annotations[i]);
if (isContext(tmpAnnotations)) {
paramsCount++;
} else {
final Type genericParameterType = genericParameterTypes[i];
final List<Parameter> tmpParameters = collectParameters(genericParameterType, tmpAnnotations);
if (tmpParameters.size() >= 1) {
for (Parameter tmpParameter : tmpParameters) {
if (ParameterProcessor.applyAnnotations(swagger, tmpParameter, genericParameterType, tmpAnnotations) != null) {
parameters.add(tmpParameter);
}
}
paramsCount++;
}
}
}
if (paramsCount >= maxParamsCount) {
maxParamsCount = paramsCount;
selected = parameters;
}
}
return selected;
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class ReaderUtils method collectFieldParameters.
/**
* Collects field-level parameters from class.
*
* @param cls is a class for collecting
* @param swagger is the instance of the Swagger
* @return the collection of supported parameters
*/
public static List<Parameter> collectFieldParameters(Class<?> cls, Swagger swagger) {
final List<Parameter> parameters = new ArrayList<Parameter>();
for (Field field : ReflectionUtils.getDeclaredFields(cls)) {
final List<Annotation> annotations = Arrays.asList(field.getAnnotations());
final Type genericType = field.getGenericType();
for (Parameter parameter : collectParameters(genericType, annotations)) {
if (ParameterProcessor.applyAnnotations(swagger, parameter, genericType, annotations) != null) {
parameters.add(parameter);
}
}
}
return parameters;
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithParamRange.
@Test(description = "scan a resource with param range")
public void scanResourceWithParamRange() {
Swagger swagger = getSwagger(ResourceWithRanges.class);
List<Parameter> params = getGetParameters(swagger, "/{id}");
PathParameter param0 = (PathParameter) params.get(0);
assertEquals(param0.getName(), "id");
assertEquals(param0.getDefaultValue(), 5);
assertEquals(param0.getMinimum(), new BigDecimal(0.0));
assertEquals(param0.getMaximum(), new BigDecimal(10.0));
PathParameter param1 = (PathParameter) params.get(1);
assertEquals(param1.getName(), "minValue");
assertEquals(param1.getMinimum(), new BigDecimal(0.0));
assertNull(param1.getMaximum(), null);
PathParameter param2 = (PathParameter) params.get(2);
assertEquals(param2.getName(), "maxValue");
assertNull(param2.getMinimum());
assertEquals(param2.getMaximum(), new BigDecimal(100.0));
PathParameter param3 = (PathParameter) params.get(3);
assertEquals(param3.getName(), "values");
IntegerProperty items = (IntegerProperty) param3.getItems();
assertEquals(items.getMinimum(), new BigDecimal(0.0));
assertEquals(items.getMaximum(), new BigDecimal(5.0));
assertEquals(items.getExclusiveMinimum(), Boolean.TRUE);
assertEquals(items.getExclusiveMaximum(), Boolean.TRUE);
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithExampleClassQuery.
@Test(description = "scan a resource with query param example (dataTypeClass)")
public void scanClassWithExampleClassQuery() {
Swagger swagger = getSwagger(ClassWithExamplePostClass.class);
Parameter param = swagger.getPaths().get("/external/info").getGet().getParameters().get(0);
QueryParameter bp = (QueryParameter) param;
assertNotNull(bp.getExample());
Object value = bp.getExample();
assertEquals("a,b,c", value);
}
Aggregations