use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ParameterProcessorTest method beanValidationArrayParametrizedMethodTest.
@Test
public void beanValidationArrayParametrizedMethodTest() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("beanValidationArrayParametrizedMethod", List.class, List.class, List.class, String.class);
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
//First param - items specified
HeaderParameter headerParam1 = new HeaderParameter().type(ArrayProperty.TYPE).items(new LongProperty());
HeaderParameter param1 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam1, genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
assertNotNull(param1);
assertEquals((int) param1.getMinItems(), 5);
assertEquals((int) param1.getMaxItems(), 10);
Property items1 = param1.getItems();
assertTrue(items1 instanceof LongProperty);
LongProperty longItems = (LongProperty) items1;
assertEquals(longItems.getMinimum(), new BigDecimal(5));
assertNull(longItems.getExclusiveMinimum());
assertEquals(longItems.getMaximum(), new BigDecimal(10));
assertNull(longItems.getExclusiveMaximum());
//Second param - items specified
HeaderParameter headerParam2 = new HeaderParameter().type(ArrayProperty.TYPE).items(new DoubleProperty());
HeaderParameter param2 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam2, genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
assertNotNull(param2);
assertEquals((int) param2.getMinItems(), 5);
assertEquals((int) param2.getMaxItems(), 10);
Property items2 = param2.getItems();
assertTrue(items2 instanceof DoubleProperty);
DoubleProperty doubleItems = (DoubleProperty) items2;
assertEquals(doubleItems.getMinimum(), new BigDecimal(5.5));
assertTrue(doubleItems.getExclusiveMinimum());
assertEquals(doubleItems.getMaximum(), new BigDecimal(10.5));
assertTrue(doubleItems.getExclusiveMaximum());
//Third param - items specified
HeaderParameter headerParam3 = new HeaderParameter().type(ArrayProperty.TYPE).items(new StringProperty());
HeaderParameter param3 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam3, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
assertNotNull(param3);
assertEquals((int) param3.getMinItems(), 5);
assertEquals((int) param3.getMaxItems(), 10);
Property items3 = param3.getItems();
assertTrue(items3 instanceof StringProperty);
StringProperty stringItems = (StringProperty) items3;
assertEquals(stringItems.getPattern(), TEST_PATTERN_REGXP);
//Fourth param - items specified
HeaderParameter headerParam4 = new HeaderParameter().type(StringProperty.TYPE);
HeaderParameter param4 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam4, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
assertNotNull(param4);
assertEquals(param4.getType(), ArrayProperty.TYPE);
assertEquals((int) param4.getMinItems(), 5);
assertEquals((int) param4.getMaxItems(), 10);
Property items4 = param4.getItems();
assertTrue(items4 instanceof StringProperty);
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ModelConverterTest method scanModelWithOffset.
@Test(description = "it tests a model with java offset")
public void scanModelWithOffset() throws IOException {
final Map<String, Model> models = readAll(ModelWithOffset.class);
assertEquals(models.size(), 1);
final Model model = models.get("ModelWithOffset");
Property property = model.getProperties().get("offset");
assertEquals(property.getType(), "string");
assertEquals(property.getFormat(), "date-time");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ModelConverterTest method setReadOnly.
@Test(description = "it should set readOnly per #854")
public void setReadOnly() {
final Map<String, Model> schemas = readAll(JacksonReadonlyModel.class);
final ModelImpl model = (ModelImpl) schemas.get("JacksonReadonlyModel");
final Property prop = model.getProperties().get("count");
assertTrue(prop.getReadOnly());
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ModelConverterTest method processModelWithPairProperties.
@Test(description = "it should process a model with org.apache.commons.lang3.tuple.Pair properties")
public void processModelWithPairProperties() {
final ModelWithTuple2.TupleAsMapModelConverter asMapConverter = new ModelWithTuple2.TupleAsMapModelConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asMapConverter);
final Map<String, Model> asMap = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asMapConverter);
assertEquals(asMap.size(), 4);
for (String item : Arrays.asList("MapOfString", "MapOfComplexLeft")) {
ModelImpl model = (ModelImpl) asMap.get(item);
assertEquals(model.getType(), "object");
assertNull(model.getProperties());
assertNotNull(model.getAdditionalProperties());
}
final ModelWithTuple2.TupleAsMapPropertyConverter asPropertyConverter = new ModelWithTuple2.TupleAsMapPropertyConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asPropertyConverter);
final Map<String, Model> asProperty = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asPropertyConverter);
assertEquals(asProperty.size(), 2);
for (Map.Entry<String, Property> entry : asProperty.get("ModelWithTuple2").getProperties().entrySet()) {
String name = entry.getKey();
Property property = entry.getValue();
if ("timesheetStates".equals(name)) {
assertEquals(property.getClass(), MapProperty.class);
} else if ("manyPairs".equals(name)) {
assertEquals(property.getClass(), ArrayProperty.class);
Property items = ((ArrayProperty) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapProperty.class);
Property stringProperty = ((MapProperty) items).getAdditionalProperties();
assertNotNull(stringProperty);
assertEquals(stringProperty.getClass(), StringProperty.class);
} else if ("complexLeft".equals(name)) {
assertEquals(property.getClass(), ArrayProperty.class);
Property items = ((ArrayProperty) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapProperty.class);
Property additionalProperty = ((MapProperty) items).getAdditionalProperties();
assertNotNull(additionalProperty);
assertEquals(additionalProperty.getClass(), RefProperty.class);
assertEquals(((RefProperty) additionalProperty).getSimpleRef(), "ComplexLeft");
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class ModelConverterTest method checkModel.
private void checkModel(Model model) {
for (Map.Entry<String, Property> entry : model.getProperties().entrySet()) {
final String name = entry.getKey();
final Property property = entry.getValue();
if (Arrays.asList("shortPrimitive", "shortObject", "intPrimitive", "intObject").contains(name)) {
checkType(property, IntegerProperty.class, "integer", "int32");
} else if (Arrays.asList("longPrimitive", "longObject").contains(name)) {
checkType(property, LongProperty.class, "integer", "int64");
} else if (Arrays.asList("floatPrimitive", "floatObject").contains(name)) {
checkType(property, FloatProperty.class, "number", "float");
} else if (Arrays.asList("doublePrimitive", "doubleObject").contains(name)) {
checkType(property, DoubleProperty.class, "number", "double");
} else if ("bigInteger".equals(name)) {
checkType(property, BaseIntegerProperty.class, "integer", null);
} else if ("bigDecimal".equals(name)) {
checkType(property, DecimalProperty.class, "number", null);
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
Aggregations