From dbec570a0ff08d78cd201eac01b62d7ea060d6ed Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 18 May 2020 20:33:13 -0700 Subject: [PATCH] Add unit test for any type conversion --- .../io/swagger/parser/test/V2ConverterTest.java | 16 ++++++++++++++++ .../src/test/resources/issue-1378.yaml | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 modules/swagger-parser-v2-converter/src/test/resources/issue-1378.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..39f2f1aa61 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 @@ -12,6 +12,7 @@ import io.swagger.v3.oas.models.media.ComposedSchema; import io.swagger.v3.oas.models.media.IntegerSchema; import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; @@ -96,6 +97,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_1378_YAML = "issue-1378.yaml"; private static final String API_BATCH_PATH = "/api/batch/"; private static final String PETS_PATH = "/pets"; @@ -852,6 +854,20 @@ public void testissue1261() throws Exception { } + @Test(description = "OpenAPI v2 converter - Schema without the 'type' keyword") + public void testissue1378() throws Exception { + OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1378_YAML); + assertNotNull(oas); + Schema schema = (Schema) oas.getComponents().getSchemas().get("Foo"); + assertNotNull(schema); + assertNotNull(schema.getProperties()); + assertNotNull(schema.getProperties().get("p1")); + assertNotNull(schema.getProperties().get("p2")); + assertTrue(schema.getProperties().get("p1") instanceof ObjectSchema); + assertTrue(schema.getProperties().get("p2").getClass().equals(Schema.class)); + assertNull(((Schema)schema.getProperties().get("p2")).getType()); + } + @Test() public void testInlineDefinitionProperty() throws Exception { SwaggerConverter converter = new SwaggerConverter(); diff --git a/modules/swagger-parser-v2-converter/src/test/resources/issue-1378.yaml b/modules/swagger-parser-v2-converter/src/test/resources/issue-1378.yaml new file mode 100644 index 0000000000..989eca792f --- /dev/null +++ b/modules/swagger-parser-v2-converter/src/test/resources/issue-1378.yaml @@ -0,0 +1,13 @@ +swagger: '2.0' +info: + title: AnyType test + version: '1.0.0' +paths: {} +definitions: + Foo: + type: object + properties: + p1: + type: object + p2: + description: test