Skip to content

Commit 6a83fb0

Browse files
authored
Merge pull request #1182 from swagger-api/issue-1147
fix for issue Reference not correctly rewritten with setResolve #1147
2 parents af70ab4 + 66e3b5f commit 6a83fb0

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIResolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public OpenAPI resolve() {
4949
pathProcessor.processPaths();
5050
componentsProcessor.processComponents();
5151

52+
5253
if(openApi.getPaths() != null) {
5354
for(String pathname : openApi.getPaths().keySet()) {
5455
PathItem pathItem = openApi.getPaths().get(pathname);

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void processComponents() {
5555
return;
5656
}
5757

58-
final Map<String, Schema> schemas = openApi.getComponents().getSchemas();
58+
5959
final Map<String, ApiResponse> responses = openApi.getComponents().getResponses();
6060
final Map<String, RequestBody> requestBodies = openApi.getComponents().getRequestBodies();
6161
final Map<String, Parameter> parameters = openApi.getComponents().getParameters();
@@ -65,13 +65,7 @@ public void processComponents() {
6565
final Map<String, Callback> callbacks = openApi.getComponents().getCallbacks();
6666
final Map<String, SecurityScheme> securitySchemes = openApi.getComponents().getSecuritySchemes();
6767

68-
//schemas
69-
if (schemas != null) {
70-
Set<String> keySet = new LinkedHashSet<>();
71-
while(schemas.keySet().size() > keySet.size()) {
72-
processSchemas(keySet, schemas);
73-
}
74-
}
68+
7569

7670
//responses
7771
if (responses != null) {
@@ -136,6 +130,16 @@ public void processComponents() {
136130
processSecuritySchemes(keySet, securitySchemes);
137131
}
138132
}
133+
134+
final Map<String, Schema> schemas = openApi.getComponents().getSchemas();
135+
136+
//schemas
137+
if (schemas != null) {
138+
Set<String> keySet = new LinkedHashSet<>();
139+
while(schemas.keySet().size() > keySet.size()) {
140+
processSchemas(keySet, schemas);
141+
}
142+
}
139143
}
140144

141145
private void processSecuritySchemes(Set<String> securitySchemeKey, Map<String, SecurityScheme> securitySchemes) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ public class OpenAPIV3ParserTest {
6666
protected int serverPort = getDynamicPort();
6767
protected WireMockServer wireMockServer;
6868

69+
@Test
70+
public void testIssue1147() {
71+
ParseOptions options = new ParseOptions();
72+
options.setResolve(true);
73+
options.setFlatten(true);
74+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1147/issue1147.yaml", null, options);
75+
OpenAPI apispec = parseResult.getOpenAPI();
76+
assertNotNull(apispec);
77+
assertEquals(((Schema)apispec.getComponents().getSchemas().get("StringObject").getProperties().get("val")).get$ref(),"#/components/schemas/String");
78+
}
79+
6980
@Test
7081
public void testIssue1148_Flatten_Dot() {
7182
ParseOptions options = new ParseOptions();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.0
2+
info:
3+
version: "1.0"
4+
title: Swagger Parser Issue
5+
paths: {}
6+
components:
7+
schemas:
8+
String:
9+
type: string
10+
StringObject:
11+
type: object
12+
properties:
13+
val:
14+
$ref: '#/components/schemas/String'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
openapi: 3.0.0
2+
info:
3+
version: "1.0"
4+
title: Swagger Parser Issue
5+
paths:
6+
/:
7+
post:
8+
requestBody:
9+
$ref: '#/components/requestBodies/RefRequestBody'
10+
responses:
11+
default:
12+
description: "Error"
13+
components:
14+
requestBodies:
15+
RefRequestBody:
16+
content:
17+
'application/json':
18+
schema:
19+
$ref: 'common.yaml#/components/schemas/StringObject'

0 commit comments

Comments
 (0)