Skip to content

Commit

Permalink
Fix for issue #616 allOf fails to resolve RELATIVE ref
Browse files Browse the repository at this point in the history
  • Loading branch information
EtonDoze committed Jan 7, 2018
1 parent dc315cf commit 00e7947
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public String processRefToExternalDefinition(String $ref, RefFormat refFormat) {
if (allOfModel instanceof RefModel) {
RefModel refModel = (RefModel) allOfModel;
if (isAnExternalRefFormat(refModel.getRefFormat())) {
refModel.set$ref(processRefToExternalDefinition(refModel.get$ref(), refModel.getRefFormat()));
String joinedRef = join(file, refModel.get$ref());
refModel.set$ref(processRefToExternalDefinition(joinedRef, refModel.getRefFormat()));
} else {
processRefToExternalDefinition(file + refModel.get$ref(), RefFormat.RELATIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,12 @@ public void checkAllOfAreTaken() {

}

@Test(description = "Issue #616 Relative references inside of 'allOf'")
public void checkAllOfWithRelativeReferencesAreFound() {
Swagger swagger = new SwaggerParser().read("src/test/resources/allOf-relative-file-references/parent.json");
assertEquals(4, swagger.getDefinitions().size());
}

@Test(description = "A string example should not be over quoted when parsing a yaml string")
public void readingSpecStringShouldNotOverQuotingStringExample() throws Exception {
SwaggerParser parser = new SwaggerParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"allOf": [
{
"$ref": "./pet.json"
},
{
"properties": {
"breed": {
"type": "string",
"example": "Labrador"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string",
"example": "Cooper"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"swagger": "2.0",
"info": {
"description": "Issue #616. This is a modified Petstore server where we have two pet definitions 1. pet and 2. fancy_pet which inherits pet using allOf."
},
"host": "petstore.swagger.io",
"basePath": "/v3",
"paths": {
"/pet": {
"get": {
"operationId": "getPetById",
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"schema": {
"$ref": "./models/pet.json"
}
}
}
}
},
"/fancy-pet": {
"get": {
"operationId": "getFancyPetById",
"parameters": [
{
"name": "fancyPetId",
"in": "path",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"schema": {
"$ref": "./models/fancy_pet.json"
}
}
}
}
}
},
"definitions": {
"DomesticPet": {
"allOf": [
{
"$ref": "./models/pet.json"
},
{
"properties": {
"description": {
"type": "string",
"example": "friendly"
}
}
}
]
},
"DancingPet": {
"allOf": [
{
"$ref": "./models/fancy_pet.json"
},
{
"properties": {
"style": {
"type": "string",
"example": "salsa"
}
}
}
]
}
}
}

0 comments on commit 00e7947

Please sign in to comment.