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 4e35d5229f..c33ac684b7 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 @@ -395,18 +395,15 @@ public Schema resolveSchema(Schema schema) { for (String key : updated.keySet()) { Schema property = updated.get(key); - if(property instanceof ObjectSchema) { - ObjectSchema op = (ObjectSchema) property; - if (op.getProperties() != model.getProperties()) { - if (property.getType() == null) { - property.setType("object"); - } - model.addProperties(key, property); - } else { - LOGGER.debug("not adding recursive properties, using generic object"); - ObjectSchema newSchema = new ObjectSchema(); - model.addProperties(key, newSchema); + if (property.getProperties() != model.getProperties()) { + if (property.getType() == null) { + property.setType("object"); } + model.addProperties(key, property); + } else { + LOGGER.debug("not adding recursive properties, using generic object"); + ObjectSchema newSchema = new ObjectSchema(); + model.addProperties(key, newSchema); } } diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java index 7f14b57997..ad61cf0839 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java @@ -1,6 +1,7 @@ package io.swagger.parser; -import io.swagger.util.Yaml; +import io.swagger.models.properties.Property; +import io.swagger.v3.core.util.Yaml; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.media.ArraySchema; @@ -8,6 +9,7 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.media.StringSchema; import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; @@ -561,6 +563,32 @@ public void testIssue1086() { Schema score = schema.getProperties().get("score"); assertEquals(score.getMultipleOf().intValue(), 1); } - + + @Test + public void testIssue1433_ResolveSchemaWithoutType() { + OpenAPIParser openApiParser = new OpenAPIParser(); + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + + OpenAPI openAPI = openApiParser.readLocation("issue_1433-resolve-schema-without-type.yaml", null, options).getOpenAPI(); + final Schema requestBodySchema = openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema(); + assertNotNull(requestBodySchema); + + final Map properties = requestBodySchema.getProperties(); + assertEquals(2, properties.size()); + + final Object bar = properties.get("bar"); + assertEquals(StringSchema.class, bar.getClass()); + + final Object input = properties.get("input"); + assertEquals(Schema.class, input.getClass()); + + final Map inputProperties = ((Schema) input).getProperties(); + assertNotNull(inputProperties); + assertEquals(1, inputProperties.size()); + + final Object baz = inputProperties.get("baz"); + assertEquals(StringSchema.class, baz.getClass()); + } } diff --git a/modules/swagger-parser/src/test/resources/issue_1433-resolve-schema-without-type.yaml b/modules/swagger-parser/src/test/resources/issue_1433-resolve-schema-without-type.yaml new file mode 100644 index 0000000000..436754ec39 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue_1433-resolve-schema-without-type.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.0 +info: + title: no type resolution + version: 1.0.0 +paths: + /foo: + post: + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/FooInput' + responses: + '200': + description: subscription successfully created +components: + schemas: + FooInput: + properties: + bar: + type: string + input: + $ref: '#/components/schemas/BazInput' + BazInput: + properties: + baz: + type: string \ No newline at end of file