use of io.swagger.v3.core.oas.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.TupleAsMapPropertyConverter asPropertyConverter = new ModelWithTuple2.TupleAsMapPropertyConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asPropertyConverter);
final Map<String, Schema> asProperty = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asPropertyConverter);
// assertEquals(asProperty.size(), 2);
Map<String, Schema> values = asProperty.get("ModelWithTuple2").getProperties();
Yaml.prettyPrint(values);
for (Map.Entry<String, Schema> entry : values.entrySet()) {
String name = entry.getKey();
Schema property = entry.getValue();
if ("timesheetStates".equals(name)) {
assertEquals(property.getClass(), MapSchema.class);
} else if ("manyPairs".equals(name)) {
assertEquals(property.getClass(), ArraySchema.class);
Schema items = ((ArraySchema) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapSchema.class);
Schema stringProperty = (Schema) ((MapSchema) items).getAdditionalProperties();
assertNotNull(stringProperty);
assertEquals(stringProperty.getClass(), StringSchema.class);
} else if ("complexLeft".equals(name)) {
assertEquals(property.getClass(), ArraySchema.class);
Schema items = ((ArraySchema) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapSchema.class);
Schema additionalProperty = (Schema) ((MapSchema) items).getAdditionalProperties();
assertNotNull(additionalProperty);
assertNotNull(additionalProperty.get$ref());
assertEquals(additionalProperty.get$ref(), "#/components/schemas/ComplexLeft");
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
Aggregations