diff --git a/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java b/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java index 298cac4e97..03d656bdc3 100644 --- a/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java +++ b/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java @@ -788,6 +788,44 @@ public Model definition(ObjectNode node, String location, ParseResult result) { impl.setUniqueItems(bp); } + bp = getBoolean("exclusiveMaximum", node, false, location, result); + if(bp != null) { + impl.setExclusiveMaximum(bp); + } + + bp = getBoolean("exclusiveMinimum", node, false, location, result); + if(bp != null) { + impl.setExclusiveMinimum(bp); + } + + value = getString("pattern", node, false, location, result); + impl.setPattern(value); + + BigDecimal maximum = getBigDecimal("maximum", node, false, location, result); + if(maximum != null) { + impl.maximum(maximum); + } + + BigDecimal minimum = getBigDecimal("minimum", node, false, location, result); + if(minimum != null) { + impl.minimum(minimum); + } + + Integer minLength = getInteger("minLength", node, false, location, result); + if(minLength != null) { + impl.setMinLength(minLength); + } + + Integer maxLength = getInteger("maxLength", node, false, location, result); + if(maxLength != null) { + impl.setMaxLength(maxLength); + } + + BigDecimal multipleOf = getBigDecimal("multipleOf", node, false, location, result); + if(multipleOf != null) { + impl.setMultipleOf(multipleOf); + } + ap = node.get("enum"); if(ap != null) { ArrayNode arrayNode = getArray("enum", node, false, location, result); diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/util/SwaggerDeserializerTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/util/SwaggerDeserializerTest.java index e142566c2c..a0e32628cb 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/util/SwaggerDeserializerTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/util/SwaggerDeserializerTest.java @@ -1404,6 +1404,110 @@ public void testIssue386() { assertNotNull(swagger); } + @Test + public void testIssue673ArrayProperties() { + String yaml = + "swagger: '2.0'\n" + + "info:\n" + + " description: 'Good'\n" + + " version: '2.0.0'\n" + + " title: 'Test'\n" + + "paths:\n" + + " /foo:\n" + + " post:\n" + + " responses:\n" + + " 200:\n" + + " description: 'OK'\n" + + "definitions:\n" + + " Fun:\n" + + " type: object\n" + + " properties:\n" + + " id:\n" + + " type: array\n" + + " uniqueItems: true\n" + + " minLength: 1\n" + + " maxLength: 100\n"; + + SwaggerParser parser = new SwaggerParser(); + SwaggerDeserializationResult result = parser.readWithInfo(yaml); + Swagger swagger = result.getSwagger(); + assertNotNull(swagger); + Property property = swagger.getDefinitions().get("Fun").getProperties().get("id"); + assertEquals(Boolean.TRUE, ((ArrayProperty)property).getUniqueItems()); + } + + @Test + public void testIssue673StringProperties() { + String yaml = + "swagger: '2.0'\n" + + "info:\n" + + " description: 'Good'\n" + + " version: '2.0.0'\n" + + " title: 'Test'\n" + + "paths:\n" + + " /foo:\n" + + " post:\n" + + " responses:\n" + + " 200:\n" + + " description: 'OK'\n" + + "definitions:\n" + + " Fun:\n" + + " type: object\n" + + " properties:\n" + + " id:\n" + + " type: string\n" + + " pattern: Pattern\n" + + " minLength: 1\n" + + " maxLength: 100\n"; + + SwaggerParser parser = new SwaggerParser(); + SwaggerDeserializationResult result = parser.readWithInfo(yaml); + Swagger swagger = result.getSwagger(); + assertNotNull(swagger); + Property property = swagger.getDefinitions().get("Fun").getProperties().get("id"); + assertEquals("Pattern", ((StringProperty)property).getPattern()); + assertEquals(new Integer(1), ((StringProperty)property).getMinLength()); + assertEquals(new Integer(100), ((StringProperty)property).getMaxLength()); + } + + @Test + public void testIssue673NumericProperties() { + String yaml = + "swagger: '2.0'\n" + + "info:\n" + + " description: 'Good'\n" + + " version: '2.0.0'\n" + + " title: 'Test'\n" + + "paths:\n" + + " /foo:\n" + + " post:\n" + + " responses:\n" + + " 200:\n" + + " description: 'OK'\n" + + "definitions:\n" + + " Fun:\n" + + " type: object\n" + + " properties:\n" + + " id:\n" + + " type: number\n" + + " minimum: 1\n" + + " maximum: 100\n" + + " exclusiveMaximum: true\n" + + " exclusiveMinimum: true\n" + + " multipleOf: 5\n"; + + SwaggerParser parser = new SwaggerParser(); + SwaggerDeserializationResult result = parser.readWithInfo(yaml); + Swagger swagger = result.getSwagger(); + assertNotNull(swagger); + Property property = swagger.getDefinitions().get("Fun").getProperties().get("id"); + assertEquals(new BigDecimal(1), ((AbstractNumericProperty)property).getMinimum()); + assertEquals(new BigDecimal(100), ((AbstractNumericProperty)property).getMaximum()); + assertEquals(new BigDecimal(5), ((AbstractNumericProperty)property).getMultipleOf()); + assertEquals(Boolean.TRUE, ((AbstractNumericProperty)property).getExclusiveMinimum()); + assertEquals(Boolean.TRUE, ((AbstractNumericProperty)property).getExclusiveMaximum()); + } + @Test public void testIssue360() { Swagger swagger = new Swagger(); diff --git a/pom.xml b/pom.xml index 7f321513ef..b3d501b43c 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ 2.4 1.6.3 - 1.5.19 + 1.5.20-SNAPSHOT 4.8.1 6.9.6 1.19