Skip to content

Commit eab9a28

Browse files
authored
Merge pull request #926 from swagger-api/issues-901-913-to-OAS3
Issues 901 - 913 to oas3
2 parents 03ff021 + 85fd5b5 commit eab9a28

File tree

12 files changed

+205
-3
lines changed

12 files changed

+205
-3
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
public enum RefType {
77
COMPONENTS("#/components/"),
8+
SCHEMAS("#/components/schemas/"),
89
PATH("#/paths/");
910

1011
private final String internalPrefix;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.swagger.v3.oas.models.media.ArraySchema;
1111
import io.swagger.v3.oas.models.media.ComposedSchema;
1212
import io.swagger.v3.oas.models.media.MediaType;
13+
import io.swagger.v3.oas.models.media.ObjectSchema;
1314
import io.swagger.v3.oas.models.media.Schema;
1415
import io.swagger.v3.oas.models.parameters.Parameter;
1516
import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -18,6 +19,7 @@
1819
import io.swagger.v3.oas.models.security.SecurityScheme;
1920
import io.swagger.v3.parser.ResolverCache;
2021
import io.swagger.v3.parser.models.RefFormat;
22+
import io.swagger.v3.parser.models.RefType;
2123
import org.apache.commons.lang3.StringUtils;
2224
import org.slf4j.LoggerFactory;
2325

@@ -199,6 +201,11 @@ private void processProperties(Map<String,Schema> subProps, String file) {
199201
&& StringUtils.isNotBlank(((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref())) {
200202
processRefSchema(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file);
201203
}
204+
}else if (prop.getValue() instanceof ObjectSchema){
205+
ObjectSchema objProp = (ObjectSchema) prop.getValue();
206+
if(objProp.getProperties() != null ){
207+
processProperties(objProp.getProperties(),file);
208+
}
202209
}
203210
}
204211
}
@@ -674,16 +681,17 @@ private void processRefSchema(Schema subRef, String externalFile) {
674681
RefFormat format = computeRefFormat(subRef.get$ref());
675682

676683
if (!isAnExternalRefFormat(format)) {
677-
subRef.set$ref(processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
684+
subRef.set$ref(RefType.SCHEMAS.getInternalPrefix()+ processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
678685
return;
679686
}
680687
String $ref = subRef.get$ref();
681688

682689
if (format.equals(RefFormat.RELATIVE)) {
683690
$ref = constructRef(subRef, externalFile);
684691
subRef.set$ref($ref);
692+
}else {
693+
processRefToExternalSchema($ref, format);
685694
}
686-
processRefToExternalSchema($ref, computeRefFormat(subRef.get$ref()));
687695
}
688696

689697

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.swagger.v3.oas.models.media.Schema;
1010
import io.swagger.v3.parser.ResolverCache;
1111
import io.swagger.v3.parser.models.RefFormat;
12+
import io.swagger.v3.parser.models.RefType;
1213
import io.swagger.v3.parser.util.RefUtils;
1314

1415
import java.util.HashMap;
@@ -201,7 +202,7 @@ private void processReferenceSchema(Schema schema) {
201202
final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
202203

203204
if (newRef != null) {
204-
schema.set$ref(newRef);
205+
schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
205206
}
206207
}
207208
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,45 @@ public class OpenAPIV3ParserTest {
5858
protected WireMockServer wireMockServer;
5959

6060

61+
@Test
62+
public void testIssue913() {
63+
OpenAPIV3Parser parser = new OpenAPIV3Parser();
64+
ParseOptions options = new ParseOptions();
65+
options.setResolve(true);
66+
final OpenAPI openAPI = parser.readLocation("issue-913/BS/ApiSpecification.yaml", null, options).getOpenAPI();
67+
Assert.assertNotNull(openAPI);
68+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("indicatorType"));
69+
Assert.assertEquals(openAPI.getComponents().getSchemas().get("indicatorType").getProperties().size(),1);
70+
}
71+
72+
@Test
73+
public void testIssue901_2() {
74+
ParseOptions options = new ParseOptions();
75+
options.setResolve(true);
76+
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec2.yaml",null,options).getOpenAPI();
77+
assertNotNull(openAPI);
78+
assertNotNull(openAPI.getComponents());
79+
ArraySchema arraySchema = (ArraySchema) openAPI.getComponents().getSchemas().get("Test.Definition").getProperties().get("stuff");
80+
String internalRef = arraySchema.getItems().get$ref();
81+
assertEquals(internalRef,"#/components/schemas/TEST.THING.OUT.Stuff");
82+
83+
84+
85+
86+
87+
}
88+
89+
@Test
90+
public void testIssue901() {
91+
ParseOptions options = new ParseOptions();
92+
options.setResolve(true);
93+
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec.yaml",null,options).getOpenAPI();
94+
assertNotNull(openAPI);
95+
String internalRef = openAPI.getPaths().get("/test").getPut().getResponses().get("200").getContent().get("application/json").getSchema().get$ref();
96+
assertEquals(internalRef,"#/components/schemas/Test.Definition");
97+
assertNotNull(openAPI.getComponents());
98+
}
99+
61100
@Test
62101
public void testIssue853() {
63102
ParseOptions options = new ParseOptions();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### Domains, a place to put your reusable components
2+
3+
4+
info:
5+
title: "aa"
6+
description: "swos552"
7+
version: '1.0.0'
8+
9+
components:
10+
schemas:
11+
Test.Definition:
12+
type: object
13+
properties:
14+
stuff:
15+
type: array
16+
items:
17+
$ref: '#/components/schemas/TESTTHING'
18+
TESTTHING:
19+
type: object
20+
properties:
21+
prop:
22+
type: string
23+
pathitems:
24+
path-test:
25+
put:
26+
description: test ref
27+
operationId: test
28+
responses:
29+
'200':
30+
description: successful operation
31+
content:
32+
application/json:
33+
schema:
34+
$ref: '#/components/schemas/Test.Definition'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### Domains, a place to put your reusable components
2+
3+
4+
info:
5+
title: "aa"
6+
description: "swos55"
7+
version: '1.0.0'
8+
9+
components:
10+
schemas:
11+
Test.Definition:
12+
type: object
13+
properties:
14+
stuff:
15+
type: array
16+
items:
17+
$ref: '#/components/schemas/TEST.THING.OUT.Stuff'
18+
TEST.THING.OUT.Stuff:
19+
type: object
20+
properties:
21+
prop:
22+
type: string
23+
pathitems:
24+
path-test:
25+
put:
26+
description: test ref
27+
operationId: test
28+
responses:
29+
'200':
30+
description: successful operation
31+
content:
32+
application/json:
33+
schema:
34+
$ref: '#/components/schemas/Test.Definition'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.1
2+
info:
3+
title: testswos55
4+
description: testswos55
5+
version: "1.01"
6+
servers:
7+
- url: ///test
8+
paths:
9+
/test:
10+
$ref: ref.yaml/#/pathitems/path-test
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.1
2+
info:
3+
title: testswos55
4+
description: testswos55
5+
version: "1.01"
6+
servers:
7+
- url: ///test
8+
paths:
9+
/test:
10+
$ref: ref2.yaml/#/pathitems/path-test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"properties": {
3+
"indicatorType": {
4+
"type": "object",
5+
"properties": {
6+
"indicator": {
7+
"type": "boolean"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"properties": {
3+
"details": {
4+
"type": "object",
5+
"properties": {
6+
"confirmationCodeRequired": {
7+
"$ref": "../Common/BasicComponents.json#/properties/indicatorType"
8+
}
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)