Search in sources :

Example 6 with ArrayProperty

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

the class JsonDeserializationTest method shouldDeserializeArrayPropertyMinItems.

@Test
public void shouldDeserializeArrayPropertyMinItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMinItems());
    assertEquals(property.getMinItems().intValue(), 1);
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) 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 7 with ArrayProperty

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

the class DefaultParameterExtension method enforcePrimitive.

private Property enforcePrimitive(Property in, int level) {
    if (in instanceof RefProperty) {
        return new StringProperty();
    }
    if (in instanceof ArrayProperty) {
        if (level == 0) {
            final ArrayProperty array = (ArrayProperty) in;
            array.setItems(enforcePrimitive(array.getItems(), level + 1));
        } else {
            return new StringProperty();
        }
    }
    return in;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 8 with ArrayProperty

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

the class GenericsTest method check2DArrayAsBodyParameter.

@Test(description = "check 2D array as body parameter")
public void check2DArrayAsBodyParameter() {
    Operation op = getOperation("test2DInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel ddArray = (ArrayModel) p.getSchema();
    assertEquals(((RefProperty) ((ArrayProperty) ddArray.getItems()).getItems()).getSimpleRef(), "Tag");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 9 with ArrayProperty

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

the class GenericsTest method checkGenericResult.

@Test(description = "check generic result")
public void checkGenericResult() {
    Operation op = swagger.getPath("/generics/testGenericResult").getGet();
    Property schema = op.getResponses().get("200").getSchema();
    assertEquals(schema.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) schema).getSimpleRef(), "GenericListWrapperTag");
    Property entries = getProperty("GenericListWrapperTag", "entries");
    assertNotEquals(entries, null);
    assertEquals(entries.getClass().getName(), ArrayProperty.class.getName());
    Property items = ((ArrayProperty) entries).getItems();
    assertEquals(items.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) items).getSimpleRef(), "Tag");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Operation(io.swagger.models.Operation) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) UUIDProperty(io.swagger.models.properties.UUIDProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 10 with ArrayProperty

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

the class PropertySerializationTest method serializeArrayStringProperty.

@Test(description = "it should serialize a string array property")
public void serializeArrayStringProperty() throws IOException {
    final ArrayProperty p = new ArrayProperty().items(new StringProperty());
    final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) Test(org.testng.annotations.Test)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)43 Property (io.swagger.models.properties.Property)30 Test (org.testng.annotations.Test)30 StringProperty (io.swagger.models.properties.StringProperty)23 Model (io.swagger.models.Model)14 MapProperty (io.swagger.models.properties.MapProperty)14 IntegerProperty (io.swagger.models.properties.IntegerProperty)12 RefProperty (io.swagger.models.properties.RefProperty)12 ModelImpl (io.swagger.models.ModelImpl)8 DoubleProperty (io.swagger.models.properties.DoubleProperty)7 LongProperty (io.swagger.models.properties.LongProperty)7 Operation (io.swagger.models.Operation)6 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)6 FloatProperty (io.swagger.models.properties.FloatProperty)5 ApiModelProperty (io.swagger.annotations.ApiModelProperty)4 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)4 BaseIntegerProperty (io.swagger.models.properties.BaseIntegerProperty)4 BooleanProperty (io.swagger.models.properties.BooleanProperty)4 DecimalProperty (io.swagger.models.properties.DecimalProperty)4 Annotation (java.lang.annotation.Annotation)4