Skip to content
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 @@ -1057,6 +1057,12 @@ public Schema convert(io.swagger.models.Model v2Model) {
if (model.getAdditionalProperties() != null) {
result.setAdditionalProperties(convert(model.getAdditionalProperties()));
}
} else if(v2Model instanceof RefModel) {
RefModel ref = (RefModel) v2Model;
if (ref.get$ref().indexOf("#/definitions") == 0) {
String updatedRef = "#/components/schemas" + ref.get$ref().substring("#/definitions".length());
result.set$ref(updatedRef);
}
}

if (v2discriminator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class V2ConverterTest {
private static final String ISSUE_600_JSON = "issue-600.json";
private static final String ISSUE_455_JSON = "issue-455.json";
private static final String ISSUE_540_JSON = "issue-540.json";
private static final String ISSUE_647_JSON = "issue-647.yaml";

private static final String API_BATCH_PATH = "/api/batch/";
private static final String PETS_PATH = "/pets";
Expand Down Expand Up @@ -132,6 +133,7 @@ public class V2ConverterTest {
private static final String SOLD = "sold";
private static final String ARRAY_VALUES = "[{\"id\":-1,\"name\":\"Marvin the Paranoid Android\"}," +
"{\"id\":1000000,\"name\":\"Zaphod Beeblebrox\",\"friends\":[15]}]";
private static final String SCHEMAS_A_REF = "#/components/schemas/A";

private static final int MAX_LENGTH = 60;
private static final int REQUIRED_SIZE = 2;
Expand Down Expand Up @@ -534,6 +536,14 @@ public void testIssue600() throws Exception {
assertEquals(required.size(), REQUIRED_SIZE);
}

@Test(description = "OpenAPI v2 converter - ref in RequestBodies are correctly updated")
public void testIssue647() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_647_JSON);

String ref = oas.getComponents().getRequestBodies().get("b").getContent().get("*/*").getSchema().get$ref();
assertEquals(ref, SCHEMAS_A_REF);
}

private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
SwaggerConverter converter = new SwaggerConverter();
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
swagger: '2.0'
info:
title: some title
version: '1.0'
host: 'localhost:8000'
schemes:
- http
- https
paths: {}
definitions:
A:
type: string
parameters:
b:
name: e
in: body
schema:
$ref: '#/definitions/A'