Search in sources :

Example 1 with ModelWithTuple2

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));
        }
    }
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ModelWithTuple2(io.swagger.v3.core.oas.models.ModelWithTuple2) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

ModelWithTuple2 (io.swagger.v3.core.oas.models.ModelWithTuple2)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)1 MapSchema (io.swagger.v3.oas.models.media.MapSchema)1 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 StringSchema (io.swagger.v3.oas.models.media.StringSchema)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1