@Test public void shouldDeserializeArrayPropertyMinItems() throws Exception { String path = "json-schema-validation/array.json"; ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getMinItems()); assertEquals(property.getMinItems().intValue(), 1); }
@Test(description = "should deserialize an array property with constraints") public void testDeserializeConstrainedArrayProperties() throws Exception { OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class); Map<String, Schema> properties = oas.getComponents().getSchemas().get("Health").getProperties(); ArraySchema withMin = (ArraySchema) properties.get("array_with_min"); assertEquals(withMin.getMinItems(), Integer.valueOf(5)); assertNull(withMin.getMaxItems()); assertNull(withMin.getUniqueItems()); ArraySchema withMax = (ArraySchema) properties.get("array_with_max"); assertNull(withMax.getMinItems()); assertEquals(withMax.getMaxItems(), Integer.valueOf(10)); assertNull(withMax.getUniqueItems()); ArraySchema withUnique = (ArraySchema) properties.get("array_with_unique"); assertNull(withUnique.getMinItems()); assertNull(withUnique.getMaxItems()); assertEquals(withUnique.getUniqueItems(), Boolean.TRUE); ArraySchema withAll = (ArraySchema) properties.get("array_with_all"); assertEquals(withAll.getMinItems(), Integer.valueOf(1)); assertEquals(withAll.getMaxItems(), Integer.valueOf(10)); assertEquals(withAll.getUniqueItems(), Boolean.TRUE); }
@Test(description = "it should includes the example in the arrayproperty") public void testArrayDeserialization() throws Exception { Operation operation = Yaml.mapper().readValue(yaml, Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); MediaType media = response.getContent().get("*/*"); Schema responseSchema = media.getSchema(); assertTrue(media.getExamples().size() == 2); assertNotNull(responseSchema); assertTrue(responseSchema instanceof ArraySchema); ArraySchema mp = (ArraySchema) responseSchema; assertEquals(mp.getMinItems(), new Integer(3)); assertEquals(mp.getMaxItems(), new Integer(100)); } }
@Test(description = "read bean validations") public void readBeanValidatorTest() { final Map<String, Schema> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class); final Schema model = schemas.get("BeanValidationsModel"); final Map<String, Schema> properties = model.getProperties(); Assert.assertTrue(model.getRequired().contains("id")); final IntegerSchema age = (IntegerSchema) properties.get("age"); Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0)); Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0)); final StringSchema password = (StringSchema) properties.get("password"); Assert.assertEquals((int) password.getMinLength(), 6); Assert.assertEquals((int) password.getMaxLength(), 20); final StringSchema email = (StringSchema) properties.get("email"); Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)"); final NumberSchema minBalance = (NumberSchema) properties.get("minBalance"); Assert.assertTrue(minBalance.getExclusiveMinimum()); final NumberSchema maxBalance = (NumberSchema) properties.get("maxBalance"); Assert.assertTrue(maxBalance.getExclusiveMaximum()); final ArraySchema items = (ArraySchema) properties.get("items"); Assert.assertEquals((int) items.getMinItems(), 2); Assert.assertEquals((int) items.getMaxItems(), 10); } }
this.additionalPropertiesType = cm.additionalPropertiesType; this.minItems = schema.getMinItems(); this.maxItems = schema.getMaxItems();