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 87a06f107c..7421d7e694 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 @@ -1069,11 +1069,15 @@ public Schema convert(io.swagger.models.Model v2Model) { result = arraySchema; } else if (v2Model instanceof ComposedModel) { ComposedModel composedModel = (ComposedModel) v2Model; - - ComposedSchema composed = Json.mapper().convertValue(v2Model, ComposedSchema.class); - + ComposedSchema composed = new ComposedSchema(); + composed.setDescription(composedModel.getDescription()); + composed.setExample(composedModel.getExample()); + if (composedModel.getExternalDocs() != null) { + composed.setExternalDocs(convert(composedModel.getExternalDocs())); + } + composed.setTitle(composedModel.getTitle()); + composed.setExtensions(convert(composedModel.getVendorExtensions())); composed.setAllOf(composedModel.getAllOf().stream().map(this::convert).collect(Collectors.toList())); - result = composed; } else { String v2discriminator = null; 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 bdc0b47d80..de162a3804 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 @@ -76,6 +76,7 @@ public class V2ConverterTest { private static final String ISSUE_672_JSON = "issue-672.json"; private static final String ISSUE_673_YAML = "issue-673.yaml"; private static final String ISSUE_676_JSON = "issue-676.json"; + private static final String ISSUE_740_YAML = "issue-740.yaml"; private static final String ISSUE_708_YAML = "issue-708.yaml"; private static final String ISSUE_755_YAML = "issue-755.yaml"; private static final String ISSUE_756_JSON = "issue-756.json"; @@ -620,6 +621,16 @@ public void testIssue708() throws Exception { assertEquals(schema.getPattern(), "^[0-9]+$"); } + @Test(description = "OpenAPI v2 converter - Migrate a schema with AllOf") + public void testIssue740() throws Exception { + final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_740_YAML); + assertNotNull(oas); + Schema schema = oas.getComponents().getSchemas().get("Action"); + assertTrue(schema instanceof ComposedSchema); + ComposedSchema composedSchema = (ComposedSchema) schema; + assertEquals(composedSchema.getAllOf().size(), 2); + } + @Test(description = "OpenAPI v2 converter - no model in body parameter") public void testIssue756() throws Exception { OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_756_JSON); diff --git a/modules/swagger-parser-v2-converter/src/test/resources/issue-740.yaml b/modules/swagger-parser-v2-converter/src/test/resources/issue-740.yaml new file mode 100644 index 0000000000..efb60aa957 --- /dev/null +++ b/modules/swagger-parser-v2-converter/src/test/resources/issue-740.yaml @@ -0,0 +1,66 @@ +swagger: '2.0' +info: + description: 'Test' + version: 1.0.0 + title: OpenAPI Test Issue 740 + license: + name: Apache-2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +host: petstore.swagger.io +basePath: /v2 +schemes: + - http +paths: + /ping: + post: + summary: test + operationId: pingOperation + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + required: true + schema: + $ref: '#/definitions/Entity' + responses: + '200': + description: OK + schema: + $ref: '#/definitions/Action' +definitions: + Entity: + type: "object" + properties: + id: + type: "string" + example: "1438752" + description: "The ID of the entity." + readOnly: true + title: "Entity" + description: "A base object for all API entities." + Action: + title: "Action" + allOf: + - $ref: "#/definitions/Entity" + - type: "object" + required: + - "action_type" + discriminator: "action_type" + properties: + name: + type: "string" + description: "The name of the action." + readOnly: true + action_type: + $ref: "#/definitions/ActionType" + ActionType: + type: "string" + title: "ActionType" + description: "Some enum" + enum: + - "value1" + - "value2" + x-swagger-router-model: "ActionTypeDto" \ No newline at end of file