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);
}
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 + "}");
}
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);
}
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());
}
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);
}
Aggregations