Skip to content

Commit f9bfb59

Browse files
committed
fix issue relative refs items and properies
1 parent 3ff3d03 commit f9bfb59

File tree

10 files changed

+338
-0
lines changed

10 files changed

+338
-0
lines changed

modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.models.*;
44
import io.swagger.models.properties.ArrayProperty;
55
import io.swagger.models.properties.MapProperty;
6+
import io.swagger.models.properties.ObjectProperty;
67
import io.swagger.models.properties.Property;
78
import io.swagger.models.properties.RefProperty;
89
import io.swagger.models.refs.RefFormat;
@@ -218,6 +219,12 @@ private void processProperties(final Map<String, Property> subProps, final Strin
218219
if (arrayProp.getItems() instanceof RefProperty) {
219220
processRefProperty((RefProperty) arrayProp.getItems(), file);
220221
}
222+
if (arrayProp.getItems() != null){
223+
if (arrayProp.getItems() instanceof ObjectProperty) {
224+
ObjectProperty objectProperty = (ObjectProperty) arrayProp.getItems();
225+
processProperties(objectProperty.getProperties(), file);
226+
}
227+
}
221228
} else if (prop.getValue() instanceof MapProperty) {
222229
MapProperty mapProp = (MapProperty) prop.getValue();
223230
if (mapProp.getAdditionalProperties() instanceof RefProperty) {

modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.swagger.models.properties.ByteArrayProperty;
2626
import io.swagger.models.properties.IntegerProperty;
2727
import io.swagger.models.properties.MapProperty;
28+
import io.swagger.models.properties.ObjectProperty;
2829
import io.swagger.models.properties.Property;
2930
import io.swagger.models.properties.RefProperty;
3031
import io.swagger.models.properties.StringProperty;
@@ -54,6 +55,19 @@
5455

5556
public class SwaggerParserTest {
5657

58+
@Test
59+
public void testIssueRelativeRefs2(){
60+
String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";
61+
Swagger swagger = new SwaggerParser().read(location, null, true);
62+
assertNotNull(swagger);
63+
Map<String, Model> definitions = swagger.getDefinitions();
64+
Assert.assertTrue(definitions.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArrayProperty);
65+
ArrayProperty arraySchema = (ArrayProperty) definitions.get("confirmMessageType_v01").getProperties().get("resources");
66+
ObjectProperty prop = (ObjectProperty) arraySchema.getItems();
67+
RefProperty refProperty = (RefProperty) prop.getProperties().get("resourceID");
68+
assertEquals(refProperty.get$ref(),"#/definitions/simpleIDType_v01");
69+
}
70+
5771
@Test
5872
public void testIssue845() {
5973
SwaggerDeserializationResult swaggerDeserializationResult = new SwaggerParser().readWithInfo("");
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "The confirm message contains the processing results for the corresponding request. A request may have its processing reported as: succeeded, partially failed, or failed.",
4+
"type": "object",
5+
"properties": {
6+
"confirmMessageID": {
7+
"description": "An identifier for the instance of the confirm message",
8+
"$ref": "./simpleIDType_v01.json"
9+
},
10+
"processID": {
11+
"description": "A process identifier if one is available, like a batch ID",
12+
"$ref": "./simpleIDType_v01.json"
13+
},
14+
"processStatus": {
15+
"description": "The process results status code for the request",
16+
"type": "string",
17+
"enum": [
18+
"success", "partial-failure", "failure"
19+
]
20+
},
21+
"resources": {
22+
"type": "array",
23+
"items": {
24+
"type": "object",
25+
"properties": {
26+
"resourceID": {
27+
"description": "A resource identifier if one is available",
28+
"$ref": "./simpleIDType_v01.json"
29+
},
30+
"resourceReference": {
31+
"description": "An optional additiona reference to the resource",
32+
"type": "string"
33+
},
34+
"resourceStatus": {
35+
"description": "The process results status code for the request",
36+
"type": "string",
37+
"enum": [
38+
"success", "partial-failure", "failure"
39+
]
40+
}
41+
}
42+
}
43+
},
44+
"links": {
45+
"type": "array",
46+
"items": {
47+
"$ref": "./linkType_v01.json"
48+
}
49+
}
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "The confirm message contains the processing results for the corresponding request. A request may have its processing reported as: succeeded, partially failed, or failed.",
4+
"type": "object",
5+
"properties": {
6+
"confirmMessageID": {
7+
"description": "An identifier for the instance of the confirm message",
8+
"$ref": "./simpleIDType_v01.json"
9+
},
10+
"processID": {
11+
"description": "A process identifier if one is available, like a batch ID",
12+
"$ref": "./simpleIDType_v01.json"
13+
},
14+
"processStatus": {
15+
"description": "The process results status code for the request",
16+
"type": "string",
17+
"enum": [
18+
"success", "partial-failure", "failure"
19+
]
20+
},
21+
"resources": {
22+
"type": "array",
23+
"items": {
24+
"type": "object",
25+
"properties": {
26+
"resourceID": {
27+
"description": "A resource identifier if one is available",
28+
"$ref": "./simpleIDType_v01.json"
29+
},
30+
"resourceReference": {
31+
"description": "An optional additiona reference to the resource",
32+
"type": "string"
33+
},
34+
"resourceStatus": {
35+
"description": "The process results status code for the request",
36+
"type": "string",
37+
"enum": [
38+
"success", "partial-failure", "failure"
39+
]
40+
}
41+
}
42+
}
43+
},
44+
"links": {
45+
"type": "array",
46+
"items": {
47+
"$ref": "./linkType_v01.json"
48+
}
49+
}
50+
}
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "date",
4+
"description": "The string representation of the date value using the ISO-8601:2000 format",
5+
"type": "string",
6+
"format": "date"
7+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "link",
4+
"description": "A link description object is used to describe link relations. In the context of a schema, it defines the link relations of the instances of the schema, and can be parameterized by the instance values. The link description format can be used on its own in regular (non-schema) documents, and use of this format can be declared by referencing the normative link description schema as the schema for the data structure that uses the links.",
5+
"type": "object",
6+
"properties": {
7+
"href": {
8+
"$ref": "./simpleIDType_v01.json"
9+
},
10+
"mediaType": {
11+
"description": "The media type that the linked resource will return (Response) in",
12+
"type": "string",
13+
"enum": [
14+
"application/gzip",
15+
"application/json",
16+
"application/msword",
17+
"application/pdf",
18+
"application/postscript",
19+
"application/vnd.ms-excel",
20+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
21+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
22+
"application/xml",
23+
"application/x-www-form-urlencoded",
24+
"image/gif",
25+
"image/jpeg",
26+
"image/png",
27+
"image/tiff",
28+
"multipart/mixed",
29+
"text/html",
30+
"text/plain",
31+
"application/vnd.visio",
32+
"image/bmp",
33+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
34+
"application/vnd.ms-powerpoint",
35+
"video/mp4",
36+
"audio/mpeg",
37+
"video/x-msvideo",
38+
"video/x-ms-wmv",
39+
"application/rtf",
40+
"application/vnd.ms-outlook",
41+
"text/csv",
42+
"video/quicktime",
43+
"application/zip",
44+
"application/illustrator",
45+
"text/xml"
46+
]
47+
},
48+
"payloadArguments": {
49+
"type": "array",
50+
"items": {
51+
"type": "object",
52+
"properties": {
53+
"argumentPath": {
54+
"description": "Argument path (typically a key field) of the payload item",
55+
"type": "string"
56+
},
57+
"argumentValue": {
58+
"description": "Argument value (typically a key field) of the payload item",
59+
"type": "string"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "simpleID",
4+
"description": "Simple (string) identifier of an object to be used when there is no appropriate specific named ID Type",
5+
"type": "string",
6+
"pattern": "^[a-zA-Z0-9.$-_\/]+$"
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "Collection of pay schedules for a given organization",
4+
"type": "object",
5+
"properties": {
6+
"testingApi": {
7+
"type": "array",
8+
"items": {
9+
"title": "testingApi",
10+
"type": "object",
11+
"properties": {
12+
"itemID": {
13+
"$ref": "../../../../common/simpleIDType_v01.json"
14+
},
15+
"testLink": {
16+
"type": "array",
17+
"items": {
18+
"$ref": "../../../../common/linkType_v01.json"
19+
}
20+
}
21+
},
22+
"additionalProperties": false
23+
}
24+
},
25+
"_confirmMessage": {
26+
"$ref": "../../../../common/confirmMessageType_v01.json"
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"description": "Collection of pay schedules for a given organization",
4+
"type": "object",
5+
"properties": {
6+
"testingApi": {
7+
"type": "array",
8+
"items": {
9+
"title": "testingApi",
10+
"type": "object",
11+
"properties": {
12+
"itemID": {
13+
"$ref": "../../../../common/simpleIDType_v01.json"
14+
},
15+
"testLink": {
16+
"type": "array",
17+
"items": {
18+
"$ref": "../../../../common/linkType_v01.json"
19+
}
20+
}
21+
},
22+
"additionalProperties": false
23+
}
24+
},
25+
"_confirmMessage": {
26+
"$ref": "../../../../common/confirmMessageType_v02.json"
27+
}
28+
}
29+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"description": "APIs to retrieve some data",
5+
"version": "1.0",
6+
"title": "TEST A NEW API",
7+
"contact": {
8+
"name": "mine",
9+
"email": "[email protected]"
10+
}
11+
},
12+
"tags": [
13+
{
14+
"name": "Test",
15+
"description": "APIs to retrieve some data"
16+
}
17+
],
18+
"paths": {
19+
"/my-domain/v1/test-system": {
20+
"get": {
21+
"description": "Retrieve relevant data",
22+
"tags": [
23+
"Test"
24+
],
25+
"summary": "Retrieve relevant data",
26+
"responses": {
27+
"200": {
28+
"description": "Request was successful",
29+
"headers": {
30+
},
31+
"schema": {
32+
"$ref": "./schemas/test-api-schema_v02.json"
33+
}
34+
},
35+
"400": {
36+
"$ref": "#/responses/400"
37+
}
38+
}
39+
}
40+
}
41+
},
42+
"definitions": {
43+
},
44+
"responses": {
45+
"200": {
46+
"description": "OK",
47+
"headers": {
48+
}
49+
},
50+
"400": {
51+
"description": "Bad Request",
52+
"headers": {
53+
},
54+
"schema": {
55+
"$ref": "../../../common/confirmMessageType_v01.json"
56+
}
57+
}
58+
},
59+
"parameters": {
60+
"asOfDate": {
61+
"name": "asOfDate",
62+
"in": "query",
63+
"description": "Filter on the records that is effective, or overlap, on the asOfDate",
64+
"required": false,
65+
"example": "2017-01-01"
66+
},
67+
"header_Accept-Language": {
68+
"name": "Accept-Language",
69+
"in": "header",
70+
"description": "Accept-Language : ( language | * ) [; q =qvalue]. Specifies the language(s) that are acceptable for the response. The optional qvalue represents a quality level for acceptable languages.",
71+
"required": false,
72+
"schema": {
73+
"type": "string"
74+
}
75+
}
76+
}
77+
78+
}

0 commit comments

Comments
 (0)