Search in sources :

Example 11 with MapProperty

use of io.swagger.models.properties.MapProperty in project swagger-core by swagger-api.

the class JsonDeserializationTest method givenMapProperty_shouldDeserializeMinProperties.

@Test
public void givenMapProperty_shouldDeserializeMinProperties() {
    String path = "json-schema-validation/map.json";
    MapProperty property = (MapProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMinProperties());
    assertEquals(property.getMinProperties().intValue(), 1);
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 12 with MapProperty

use of io.swagger.models.properties.MapProperty in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.

@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property responseSchema = response.getSchema();
    assertNotNull(responseSchema);
    MapProperty mp = (MapProperty) responseSchema;
    assertTrue(mp.getVendorExtensions().size() > 0);
    assertNotNull(mp.getVendorExtensions().get("x-foo"));
    assertEquals(mp.getVendorExtensions().get("x-foo"), "vendor x");
}
Also used : Response(io.swagger.models.Response) MapProperty(io.swagger.models.properties.MapProperty) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 13 with MapProperty

use of io.swagger.models.properties.MapProperty in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeLongMapProperty.

@Test(description = "it should deserialize a long MapProperty")
public void deserializeLongMapProperty() throws IOException {
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int64\"}}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "object");
    assertEquals(p.getClass(), MapProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 14 with MapProperty

use of io.swagger.models.properties.MapProperty in project swagger-core by swagger-api.

the class ContainerTest method testMap.

@Test
public void testMap() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(MapBean.class);
    final Map<String, Property> props = model.getProperties();
    assertEquals(1, props.size());
    final Property prop = props.get("stuff");
    assertNotNull(prop);
    assertEquals(prop.getType(), "object");
    final Property items = ((MapProperty) prop).getAdditionalProperties();
    assertNotNull(items);
    assertEquals(items.getType(), "string");
    assertEquals(items.getFormat(), "date-time");
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) Model(io.swagger.models.Model) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 15 with MapProperty

use of io.swagger.models.properties.MapProperty in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeIntegerMapProperty.

@Test(description = "it should deserialize a integer MapProperty")
public void deserializeIntegerMapProperty() throws IOException {
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "object");
    assertEquals(p.getClass(), MapProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

MapProperty (io.swagger.models.properties.MapProperty)19 Property (io.swagger.models.properties.Property)15 Test (org.testng.annotations.Test)14 ArrayProperty (io.swagger.models.properties.ArrayProperty)12 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 StringProperty (io.swagger.models.properties.StringProperty)10 RefProperty (io.swagger.models.properties.RefProperty)8 Model (io.swagger.models.Model)6 LongProperty (io.swagger.models.properties.LongProperty)5 ModelImpl (io.swagger.models.ModelImpl)4 DoubleProperty (io.swagger.models.properties.DoubleProperty)4 FloatProperty (io.swagger.models.properties.FloatProperty)4 ObjectProperty (io.swagger.models.properties.ObjectProperty)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 ApiModelProperty (io.swagger.annotations.ApiModelProperty)3 Operation (io.swagger.models.Operation)3 RefModel (io.swagger.models.RefModel)3 Response (io.swagger.models.Response)3 BooleanProperty (io.swagger.models.properties.BooleanProperty)3 DateProperty (io.swagger.models.properties.DateProperty)3