From 79daf871f8f9b74fb46a4cc6432f55ec53b7515b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 15 May 2020 12:32:03 -0700 Subject: [PATCH 1/2] add unit test for additional properties --- .../swagger/parser/test/V2ConverterTest.java | 13 ++++++++++ .../src/test/resources/issue-1369.yaml | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 modules/swagger-parser/src/test/resources/issue-1369.yaml diff --git a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java index da1d632148..d960e50555 100644 --- a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java +++ b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java @@ -96,6 +96,7 @@ public class V2ConverterTest { private static final String ISSUE_1113_YAML = "issue-1113.yaml"; private static final String ISSUE_1164_YAML = "issue-1164.yaml"; private static final String ISSUE_1261_YAML = "issue-1261.yaml"; + private static final String ISSUE_1369_YAML = "issue-1369.yaml"; private static final String API_BATCH_PATH = "/api/batch/"; private static final String PETS_PATH = "/pets"; @@ -852,6 +853,18 @@ public void testissue1261() throws Exception { } + @Test(description = "OpenAPI v2 converter - verifies the additionalProperties") + public void testissue1369() throws Exception { + OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1369_YAML); + assertNotNull(oas); + Schema schema = (Schema) oas.getComponents().getSchemas().get("S1"); + assertNotNull(schema.getAdditionalProperties()); + schema = (Schema) oas.getComponents().getSchemas().get("S2"); + assertNotNull(schema.getAdditionalProperties()); + schema = (Schema) oas.getComponents().getSchemas().get("S3"); + assertNull(schema.getAdditionalProperties()); + } + @Test() public void testInlineDefinitionProperty() throws Exception { SwaggerConverter converter = new SwaggerConverter(); diff --git a/modules/swagger-parser/src/test/resources/issue-1369.yaml b/modules/swagger-parser/src/test/resources/issue-1369.yaml new file mode 100644 index 0000000000..06eedb3c95 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-1369.yaml @@ -0,0 +1,25 @@ +swagger: '2.0' +info: + title: additionalProperties test + version: '1.0.0' +paths: {} + +definitions: + S1: + type: object + properties: + foo: + type: string + additionalProperties: false + S2: + type: object + properties: + bar: + type: string + additionalProperties: + type: string + S3: + type: object + properties: + bar: + type: string From ae09e900798378f0584923e05cb7333f850b87b5 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 15 May 2020 13:13:40 -0700 Subject: [PATCH 2/2] Unit test for additional Properties --- .../v3/parser/converter/SwaggerConverter.java | 2 +- .../swagger/parser/test/V2ConverterTest.java | 19 +++++++++++++++---- .../src/test/resources/issue-1369.yaml | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) rename modules/{swagger-parser => swagger-parser-v2-converter}/src/test/resources/issue-1369.yaml (74%) diff --git a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java index 576a37820e..10026a678c 100644 --- a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java +++ b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java @@ -961,7 +961,7 @@ private Schema convert(Property schema) { FileSchema fileSchema = Json.mapper().convertValue(schema, FileSchema.class); result = fileSchema; - }else { + } else { result = Json.mapper().convertValue(schema, Schema.class); result.setExample(schema.getExample()); diff --git a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java index d960e50555..76f0aebf77 100644 --- a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java +++ b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java @@ -857,12 +857,23 @@ public void testissue1261() throws Exception { public void testissue1369() throws Exception { OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1369_YAML); assertNotNull(oas); - Schema schema = (Schema) oas.getComponents().getSchemas().get("S1"); + Schema schema = (Schema) oas.getComponents().getSchemas().get("Foo1"); + assertNotNull(schema); + assertNull(schema.getAdditionalProperties()); + + schema = (Schema) oas.getComponents().getSchemas().get("Foo2"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertEquals(schema.getAdditionalProperties(), Boolean.TRUE); + + schema = (Schema) oas.getComponents().getSchemas().get("Foo3"); + assertNotNull(schema); assertNotNull(schema.getAdditionalProperties()); - schema = (Schema) oas.getComponents().getSchemas().get("S2"); + assertEquals(schema.getAdditionalProperties(), Boolean.FALSE); + + schema = (Schema) oas.getComponents().getSchemas().get("Foo4"); + assertNotNull(schema); assertNotNull(schema.getAdditionalProperties()); - schema = (Schema) oas.getComponents().getSchemas().get("S3"); - assertNull(schema.getAdditionalProperties()); } @Test() diff --git a/modules/swagger-parser/src/test/resources/issue-1369.yaml b/modules/swagger-parser-v2-converter/src/test/resources/issue-1369.yaml similarity index 74% rename from modules/swagger-parser/src/test/resources/issue-1369.yaml rename to modules/swagger-parser-v2-converter/src/test/resources/issue-1369.yaml index 06eedb3c95..56225905bd 100644 --- a/modules/swagger-parser/src/test/resources/issue-1369.yaml +++ b/modules/swagger-parser-v2-converter/src/test/resources/issue-1369.yaml @@ -5,21 +5,27 @@ info: paths: {} definitions: - S1: + Foo1: + type: object + properties: + bar: + type: string + Foo2: type: object properties: foo: type: string additionalProperties: false - S2: + Foo3: type: object properties: - bar: + foo: type: string - additionalProperties: - type: string - S3: + additionalProperties: true + Foo4: type: object properties: bar: type: string + additionalProperties: + type: string