Search in sources :

Example 26 with ArrayProperty

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

the class BeanValidatorTest method readBeanValidatorTest.

@Test(description = "read bean validations")
public void readBeanValidatorTest() {
    final Map<String, Model> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class);
    final Model model = schemas.get("BeanValidationsModel");
    final Map<String, Property> properties = model.getProperties();
    final IntegerProperty age = (IntegerProperty) properties.get("age");
    Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0));
    Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0));
    final StringProperty password = (StringProperty) properties.get("password");
    Assert.assertEquals((int) password.getMinLength(), 6);
    Assert.assertEquals((int) password.getMaxLength(), 20);
    final StringProperty email = (StringProperty) properties.get("email");
    Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)");
    final DoubleProperty minBalance = (DoubleProperty) properties.get("minBalance");
    Assert.assertTrue(minBalance.getExclusiveMinimum());
    final DoubleProperty maxBalance = (DoubleProperty) properties.get("maxBalance");
    Assert.assertTrue(maxBalance.getExclusiveMaximum());
    final ArrayProperty items = (ArrayProperty) properties.get("items");
    Assert.assertEquals((int) items.getMinItems(), 2);
    Assert.assertEquals((int) items.getMaxItems(), 10);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BeanValidationsModel(io.swagger.models.BeanValidationsModel) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 27 with ArrayProperty

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

the class ByteConverterTest method testByteArray.

@Test
public void testByteArray() {
    Model model = new ModelImpl().property("byteArray", new ArrayProperty(new BinaryProperty()));
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteArray\" : {" + NEWLINE + "      \"type\" : \"array\"," + NEWLINE + "      \"items\" : {" + NEWLINE + "        \"type\" : \"string\"," + NEWLINE + "        \"format\" : \"binary\"" + NEWLINE + "      }" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) BinaryProperty(io.swagger.models.properties.BinaryProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 28 with ArrayProperty

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

the class JsonDeserializationTest method shouldDeserializeArrayPropertyMaxItems.

@Test
public void shouldDeserializeArrayPropertyMaxItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMaxItems());
    assertEquals(property.getMaxItems().intValue(), 10);
}
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 29 with ArrayProperty

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

the class JsonDeserializationTest method shouldDeserializeArrayPropertyUniqueItems.

@Test
public void shouldDeserializeArrayPropertyUniqueItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getUniqueItems());
    assertTrue(property.getUniqueItems());
}
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 30 with ArrayProperty

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

the class JsonDeserializationTest method testDeserializeConstrainedArrayProperties.

@Test(description = "should deserialize an array property with constraints")
public void testDeserializeConstrainedArrayProperties() throws Exception {
    Swagger swagger = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", Swagger.class);
    Map<String, Property> properties = swagger.getDefinitions().get("Health").getProperties();
    ArrayProperty withMin = (ArrayProperty) properties.get("array_with_min");
    assertEquals(withMin.getMinItems(), Integer.valueOf(5));
    assertNull(withMin.getMaxItems());
    assertNull(withMin.getUniqueItems());
    ArrayProperty withMax = (ArrayProperty) properties.get("array_with_max");
    assertNull(withMax.getMinItems());
    assertEquals(withMax.getMaxItems(), Integer.valueOf(10));
    assertNull(withMax.getUniqueItems());
    ArrayProperty withUnique = (ArrayProperty) properties.get("array_with_unique");
    assertNull(withUnique.getMinItems());
    assertNull(withUnique.getMaxItems());
    assertEquals(withUnique.getUniqueItems(), Boolean.TRUE);
    ArrayProperty withAll = (ArrayProperty) properties.get("array_with_all");
    assertEquals(withAll.getMinItems(), Integer.valueOf(1));
    assertEquals(withAll.getMaxItems(), Integer.valueOf(10));
    assertEquals(withAll.getUniqueItems(), Boolean.TRUE);
}
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)

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