From 61a8e3683a1912c9529102b33c131f3a44f2d576 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Wed, 5 Aug 2020 15:04:07 -0500 Subject: [PATCH] fix for issue #1398 --- .../v3/parser/util/OpenAPIDeserializer.java | 6 ++++- .../v3/parser/test/OpenAPIV3ParserTest.java | 6 +++++ .../src/test/resources/issue1398.yaml | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 modules/swagger-parser-v3/src/test/resources/issue1398.yaml diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java index e83b54c16e..b197b57a93 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java @@ -2189,7 +2189,11 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){ BigDecimal bigDecimal = getBigDecimal("multipleOf",node,false,location,result); if(bigDecimal != null) { - schema.setMultipleOf(bigDecimal); + if(bigDecimal.intValue() > 0) { + schema.setMultipleOf(bigDecimal); + }else{ + result.warning(location,"multipleOf value must be > 0"); + } } bigDecimal = getBigDecimal("maximum", node, false, location, result); diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index b4d19c8519..3e37694d7d 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -82,6 +82,12 @@ public class OpenAPIV3ParserTest { protected int serverPort = getDynamicPort(); protected WireMockServer wireMockServer; + @Test + public void testIssue1398() { + ParseOptions options = new ParseOptions(); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue1398.yaml", null, options); + assertEquals(result.getMessages().get(0), "attribute paths.'/pet/{petId}'(get).parameters.[petId].schemas.multipleOf value must be > 0"); + } @Test public void testIssue1367() { diff --git a/modules/swagger-parser-v3/src/test/resources/issue1398.yaml b/modules/swagger-parser-v3/src/test/resources/issue1398.yaml new file mode 100644 index 0000000000..f289462022 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue1398.yaml @@ -0,0 +1,26 @@ +openapi: 3.0.1 +info: + title: Swagger Petstore + description: 'This is a sample server Petstore server' + version: 1.0.0 +servers: + - url: http://mytestServer/{v1} + variables: + v2: + default: 'd' +paths: + '/pet/{petId}': + get: + summary: Find pet by ID + description: Returns a single pet + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type : integer + multipleOf: -10 + responses: + '200': + description: successful operation \ No newline at end of file