Skip to content

Commit cc2190c

Browse files
authored
Merge pull request #849 from swagger-api/issue_relative_ref_OAS3
fix issue relative ref array property items
2 parents e3ca120 + 5e83e70 commit cc2190c

File tree

18 files changed

+656
-4
lines changed

18 files changed

+656
-4
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ComponentsProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void processComponents() {
5454
if (openApi.getComponents() == null){
5555
return;
5656
}
57+
5758
final Map<String, Schema> schemas = openApi.getComponents().getSchemas();
5859
final Map<String, ApiResponse> responses = openApi.getComponents().getResponses();
5960
final Map<String, RequestBody> requestBodies = openApi.getComponents().getRequestBodies();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ private void processProperties(Map<String,Schema> subProps, String file) {
186186
StringUtils.isNotBlank(arrayProp.getItems().get$ref())) {
187187
processRefSchema(arrayProp.getItems(), file);
188188
}
189+
if (arrayProp.getItems() != null && arrayProp.getItems().getProperties() != null ) {
190+
processProperties(arrayProp.getItems().getProperties(), file);
191+
}
189192
} else if (prop.getValue().getAdditionalProperties() != null && prop.getValue().getAdditionalProperties() instanceof Schema) {
190193
Schema mapProp = (Schema) prop.getValue().getAdditionalProperties();
191194
if (mapProp.get$ref() != null) {
@@ -675,6 +678,7 @@ private void processRefSchema(Schema subRef, String externalFile) {
675678
return;
676679
}
677680
String $ref = subRef.get$ref();
681+
678682
if (format.equals(RefFormat.RELATIVE)) {
679683
$ref = constructRef(subRef, externalFile);
680684
subRef.set$ref($ref);

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class OpenAPIV3ParserTest {
5959
protected int serverPort = getDynamicPort();
6060
protected WireMockServer wireMockServer;
6161

62+
6263
@Test
6364
public void testIssue837() {
6465
ParseOptions options = new ParseOptions();

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package io.swagger.parser;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import io.swagger.v3.core.util.Yaml;
3+
4+
55
import io.swagger.v3.oas.models.Components;
66
import io.swagger.v3.oas.models.OpenAPI;
77
import io.swagger.v3.oas.models.media.ArraySchema;
88
import io.swagger.v3.oas.models.media.Schema;
99
import io.swagger.v3.oas.models.PathItem;
10-
import io.swagger.v3.oas.models.media.Schema;
10+
1111
import io.swagger.v3.oas.models.parameters.Parameter;
1212
import io.swagger.v3.oas.models.parameters.RequestBody;
13+
1314
import io.swagger.v3.parser.core.models.ParseOptions;
1415
import io.swagger.v3.parser.core.models.SwaggerParseResult;
1516
import io.swagger.v3.core.util.Json;
@@ -19,7 +20,7 @@
1920
import java.util.Map;
2021

2122
import java.util.List;
22-
import java.util.Map;
23+
2324

2425
import static org.testng.Assert.assertEquals;
2526
import static org.testng.Assert.assertNotNull;
@@ -354,6 +355,7 @@ public void testIssue813() throws Exception {
354355
}
355356

356357
@Test
358+
357359
public void testIssue844() {
358360
OpenAPIParser openApiParser = new OpenAPIParser();
359361
ParseOptions options = new ParseOptions();
@@ -363,4 +365,42 @@ public void testIssue844() {
363365
assertNotNull(openAPI);
364366
assertEquals(openAPI.getPaths().get("/pets/{id}").getGet().getParameters().get(0).getIn(), "header");
365367
}
368+
@Test
369+
public void testIssueRelativeRefs2(){
370+
String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";
371+
ParseOptions po = new ParseOptions();
372+
po.setResolve(true);
373+
SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
374+
375+
assertNotNull(result.getOpenAPI());
376+
OpenAPI openAPI = result.getOpenAPI();
377+
378+
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
379+
Assert.assertTrue(schemas.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArraySchema);
380+
381+
ArraySchema arraySchema = (ArraySchema) schemas.get("confirmMessageType_v01").getProperties().get("resources");
382+
Schema prop = (Schema) arraySchema.getItems().getProperties().get("resourceID");
383+
384+
assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01");
385+
}
386+
387+
@Test
388+
public void testIssueRelativeRefs1(){
389+
String location = "specs2/my-domain/test-api/v1/test-api-swagger_v1.json";
390+
ParseOptions po = new ParseOptions();
391+
po.setResolve(true);
392+
SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
393+
394+
assertNotNull(result.getOpenAPI());
395+
OpenAPI openAPI = result.getOpenAPI();
396+
397+
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
398+
Assert.assertTrue(schemas.get("test-api-schema_v01").getProperties().get("testingApi") instanceof ArraySchema);
399+
400+
ArraySchema arraySchema = (ArraySchema) schemas.get("test-api-schema_v01").getProperties().get("testingApi");
401+
Schema prop = (Schema) arraySchema.getItems().getProperties().get("itemID");
402+
403+
assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01");
404+
405+
}
366406
}
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+
}
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+
}

0 commit comments

Comments
 (0)