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 @@ -197,7 +197,7 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
model = response.getResponseSchema();
if (model instanceof RefModel) {
RefModel refModel = (RefModel) model;
if (RefUtils.isAnExternalRefFormat(refFormat)) {
if (RefUtils.isAnExternalRefFormat(refModel.getRefFormat())) {
processRefModel(refModel, $ref);
} else {
processRefToExternalDefinition(file + refModel.get$ref(), RefFormat.RELATIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ public void testLoadRelativeFileTree_Yaml() throws Exception {
assertNotNull(Yaml.mapper().writeValueAsString(swagger));
}

@Test
public void testLoadnestedExternalResponseReferencesFile_Yaml() throws Exception {
final Swagger swagger = doRelativeResponseFileTest("src/test/resources/nested-external-response-references/swagger-root.yaml");
assertNotNull(Yaml.mapper().writeValueAsString(swagger));
}

@Test
public void testLoadRecursiveExternalDef() throws Exception {
SwaggerParser parser = new SwaggerParser();
Expand Down Expand Up @@ -785,6 +791,46 @@ private Swagger doRelativeFileTest(String location) {
return swagger;
}

private Swagger doRelativeResponseFileTest(String location) {
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult readResult = parser.readWithInfo(location, null, true);

if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final Swagger swagger = readResult.getSwagger();

Json.prettyPrint(swagger);

final Path path = swagger.getPath("/users");
assertEquals(path.getClass(), Path.class); //we successfully converted the RefPath to a Path

final Operation operation = path.getGet();

final Map<String, Response> responsesMap = operation.getResponses();

assertResponse(swagger, responsesMap, "200", "OK", "#/definitions/User");

final Map<String, Model> definitions = swagger.getDefinitions();
final ModelImpl refInDefinitions = (ModelImpl) definitions.get("UserX");
expectedPropertiesInModel(refInDefinitions, "address");

final ModelImpl refInDefinitionsAddress = (ModelImpl) definitions.get("Address");
expectedPropertiesInModel(refInDefinitionsAddress, "postal", "country");

final ModelImpl refInDefinitionsCountry = (ModelImpl) definitions.get("Country");
expectedPropertiesInModel(refInDefinitionsCountry, "name");

final ModelImpl refInDefinitionsAddress_2 = (ModelImpl) definitions.get("Address_2");
expectedPropertiesInModel(refInDefinitionsAddress_2, "postal", "country");

final ModelImpl refInDefinitionsCountry_2 = (ModelImpl) definitions.get("Country_2");
expectedPropertiesInModel(refInDefinitionsCountry_2, "name");

return swagger;
}


private void expectedPropertiesInModel(ModelImpl model, String... expectedProperties) {
assertEquals(model.getProperties().size(), expectedProperties.length);
for (String expectedProperty : expectedProperties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
swagger: "2.0"
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths: {}

definitions:

Country:
type: object
properties:
name:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
swagger: "2.0"
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths: {}

responses:
Ok200:
description: OK
schema:
$ref: '../swagger-root.yaml#/definitions/User'

Ok201:
description: OK
schema:
$ref: '#/definitions/User'

definitions:
User:
$ref: '../sub-folder/sub-folder2/common-address.yaml#/definitions/Address'
#Still a BUG: Should take into account that the like is relative to this file!
# $ref: 'sub-folder2/common-address.yaml#/definitions/Address'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
swagger: "2.0"
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths: {}

definitions:

Address:
type: object
properties:
postal:
type: string
country:
$ref: '../common-country.yaml#/definitions/Country'
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
swagger: "2.0"
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths:
/users:
get:
summary: Returns a list of users.
description: Optional extended description in Markdown.
produces:
- application/json
responses:
200:
$ref: 'sub-folder/common-responses.yaml#/responses/Ok200'
201:
$ref: './sub-folder/common-responses.yaml#/responses/Ok201'

definitions:
UserX:
type: object
properties:
address:
$ref: './sub-folder/sub-folder2/common-address.yaml#/definitions/Address'

User:
$ref: './sub-folder/sub-folder2/common-address.yaml#/definitions/Address'