Search in sources :

Example 1 with ModelWithTuple2

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));
        }
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ModelWithTuple2(io.swagger.models.ModelWithTuple2) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) AbstractModelWithApiModel(io.swagger.models.composition.AbstractModelWithApiModel) Model(io.swagger.models.Model) ModelWithApiModel(io.swagger.models.ModelWithApiModel) EmptyModel(io.swagger.models.EmptyModel) JodaDateTimeModel(io.swagger.models.JodaDateTimeModel) JacksonReadonlyModel(io.swagger.models.JacksonReadonlyModel) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Aggregations

ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 EmptyModel (io.swagger.models.EmptyModel)1 JacksonReadonlyModel (io.swagger.models.JacksonReadonlyModel)1 JodaDateTimeModel (io.swagger.models.JodaDateTimeModel)1 Model (io.swagger.models.Model)1 ModelImpl (io.swagger.models.ModelImpl)1 ModelWithApiModel (io.swagger.models.ModelWithApiModel)1 ModelWithTuple2 (io.swagger.models.ModelWithTuple2)1 AbstractModelWithApiModel (io.swagger.models.composition.AbstractModelWithApiModel)1 ModelWithUrlProperty (io.swagger.models.composition.ModelWithUrlProperty)1 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 BaseIntegerProperty (io.swagger.models.properties.BaseIntegerProperty)1 DecimalProperty (io.swagger.models.properties.DecimalProperty)1 DoubleProperty (io.swagger.models.properties.DoubleProperty)1 FloatProperty (io.swagger.models.properties.FloatProperty)1 IntegerProperty (io.swagger.models.properties.IntegerProperty)1 LongProperty (io.swagger.models.properties.LongProperty)1 MapProperty (io.swagger.models.properties.MapProperty)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1