diff --git a/.editorconfig b/.editorconfig index fba6473b28..ab2fe76e06 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,7 @@ root = true # Indentation style # Possible values - tab, space indent_style = space +end_of_line = lf # File character encoding # Possible values - latin1, utf-8, utf-16be, utf-16le diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java index 497260ab8a..d64ef7708d 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java @@ -493,13 +493,6 @@ public Schema resolveSchema(Schema schema) { Schema property = updated.get(key); if (property.getProperties() != model.getProperties()) { - if (!hasSchemaType(property)) { - if (SpecVersion.V30.equals(property.getSpecVersion())) { - property.setType("object"); - } else { - property.addType("object"); - } - } model.addProperties(key, property); } else { LOGGER.debug("not adding recursive properties, using generic object"); diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java index 36117dd216..c301bce695 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java @@ -783,7 +783,16 @@ public void testIssue1706() { assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ObjectSchema); } + @Test + public void testIssue2113() { + ParseOptions options = new ParseOptions(); + options.setResolve(true); + options.setResolveFully(true); + OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue_2113.yaml", auths, options).getOpenAPI(); + ObjectSchema schema = (ObjectSchema) openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema(); + assertNull(schema.getProperties().get("goo").getType()); + } @Test public void selfReferenceTest() { diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserSchemaTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserSchemaTest.java index a6e9d738d1..d054ec1a85 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserSchemaTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserSchemaTest.java @@ -165,7 +165,7 @@ private void tearDownWireMockServer() { public void test$idUrlExternal() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").toURI().toASCIIString(), null, p); compare("$id-uri-external", swaggerParseResult); } @@ -173,7 +173,7 @@ private void tearDownWireMockServer() { public void test$idUrlEnclosing() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-enclosing/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-enclosing/root.json").toURI().toASCIIString(), null, p); compare("$id-uri-enclosing", swaggerParseResult); } @@ -181,14 +181,14 @@ private void tearDownWireMockServer() { public void test$idUrlDirect() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").toURI().toASCIIString(), null, p); compare("$id-uri-direct", swaggerParseResult); } @Test public void test$idUrlUnresolvable() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").toURI().toASCIIString(), null, p); compare("$id-unresolvable", swaggerParseResult); } @@ -196,7 +196,7 @@ private void tearDownWireMockServer() { public void testAnchorExt() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-external/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-external/root.json").toURI().toASCIIString(), null, p); compare("$anchor-external", swaggerParseResult); } @@ -204,7 +204,7 @@ public void testAnchorExt() throws Exception { public void testAnchorInt() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-internal/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-internal/root.json").toURI().toASCIIString(), null, p); compare("$anchor-internal", swaggerParseResult); } @@ -212,7 +212,7 @@ public void testAnchorInt() throws Exception { public void testAnchorUnresolve() throws Exception { ParseOptions p = new ParseOptions(); p.setResolve(true); - SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-not-found/root.json").getAbsolutePath(), null, p); + SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-not-found/root.json").toURI().toASCIIString(), null, p); compare("$anchor-not-found", swaggerParseResult); } @@ -220,7 +220,7 @@ public void compare(String dir, SwaggerParseResult result) throws Exception { ObjectMapper mapper = Json31.mapper().copy(); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); - String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI()); + String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI()).replace("\r\n", "\n"); org.testng.Assert.assertEquals(actual, FileUtils.readFileToString(new File("src/test/resources/3.1.0/dereference/schema/" + dir + "/dereferenced.json"))); } diff --git a/modules/swagger-parser-v3/src/test/resources/issue_2113.yaml b/modules/swagger-parser-v3/src/test/resources/issue_2113.yaml new file mode 100644 index 0000000000..4076cb01ef --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue_2113.yaml @@ -0,0 +1,29 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Issue X +servers: + - url: http://petstore.swagger.io/api +paths: + /foo: + post: + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Foo' + required: true + responses: + 200: + description: ok +components: + schemas: + Foo: + type: object + allOf: + - $ref: "#/components/schemas/Goo" + Goo: + type: object + properties: + goo: + title: "Goo" \ No newline at end of file