Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"