use of io.swagger.models.ModelWithTuple2 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));
}
}
}
Aggregations