Skip to content

Commit 6cbc377

Browse files
authored
Merge pull request #1994 from swagger-api/parser-resolving-duplicated-path
fix parser dereferencing when pathItems are the same
2 parents c690d8d + 631c2fc commit 6cbc377

File tree

6 files changed

+167
-7
lines changed

6 files changed

+167
-7
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,18 @@ public PathItem processRefToExternalPathItem(String $ref, RefFormat refFormat) {
270270

271271
final String possiblyConflictingDefinitionName = computeDefinitionName($ref);
272272

273-
PathItem existingPathItem = paths.get(possiblyConflictingDefinitionName);
273+
PathItem existingPathItem = paths.get("/"+possiblyConflictingDefinitionName);
274274

275275
if (existingPathItem != null) {
276276
LOGGER.debug("A model for " + existingPathItem + " already exists");
277277
if(existingPathItem.get$ref() != null) {
278278
// use the new model
279279
existingPathItem = null;
280+
}else {
281+
return pathItem;
280282
}
281283
}
284+
282285
newRef = possiblyConflictingDefinitionName;
283286
cache.putRenamedRef($ref, newRef);
284287

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ protected void updateRefs(ApiResponse response, String pathRef) {
172172
if(response.getContent() != null) {
173173
Map<String, MediaType> content = response.getContent();
174174
for (String key: content.keySet()) {
175-
MediaType mediaType = content.get(key);
176-
if (mediaType.getSchema() != null) {
177-
updateRefs(mediaType.getSchema(), pathRef);
178-
}
179175
Map<String, Example> examples = content.get(key).getExamples();
180176
if (examples != null) {
181177
for( Example example:examples.values()){

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@
4343
public class OpenAPIV3ParserTest {
4444
List<AuthorizationValue> auths = new ArrayList<>();
4545

46+
47+
@Test
48+
public void testFailedToResolveExternalReferences() {
49+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
50+
ParseOptions options = new ParseOptions();
51+
options.setResolve(true);
52+
SwaggerParseResult parseResult = openApiParser.readLocation("resolve-external-ref/failedToResolveExternalRefs.yaml", null, options);
53+
OpenAPI openAPI = parseResult.getOpenAPI();
54+
55+
Assert.assertTrue(openAPI.getPaths().get("/permAssignments").get$ref() == null);
56+
Assert.assertEquals(openAPI.getPaths().get("/permAssignments").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
57+
Assert.assertTrue(openAPI.getPaths().get("/permAssignmentChangeRequests").get$ref() == null);
58+
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChangeRequests").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
59+
Assert.assertTrue(openAPI.getPaths().get("/permAssignmentChange").get$ref() == null);
60+
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("201").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/Error");
61+
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("404").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/RemoteError");
62+
63+
}
64+
4665
@Test
4766
public void testIssueDereferencingComposedSchemaOneOf() {
4867
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
@@ -3141,8 +3160,6 @@ public void testIssue_1746_headers_relative_paths() {
31413160
options.setResolve(true);
31423161
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1746/petstore.yml", null, options);
31433162
OpenAPI openAPI = parseResult.getOpenAPI();
3144-
3145-
31463163
assertEquals(openAPI.getPaths().get("/pets").getGet().getResponses().get("200").getHeaders().get("x-next").get$ref(), "#/components/headers/LocationInHeaders");
31473164
}
31483165
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.3
2+
info:
3+
version: 1.0.0
4+
title: Novo to Back Office (Financials)
5+
description: This API contains Novo to Back Office Integrations (Financials)
6+
servers:
7+
- description: PeopleSoft Financials
8+
url: www
9+
10+
security:
11+
- basicAuth: []
12+
13+
paths:
14+
/permAssignments:
15+
$ref: 'resolve-external-ref/pathItems.yaml#/components/pathitems/permAssignments'
16+
/permAssignmentChangeRequests:
17+
$ref: 'resolve-external-ref/pathItems.yaml#/components/pathitems/permAssignments'
18+
/permAssignmentChange:
19+
$ref: 'resolve-external-ref/pathItems.yaml#/components/pathitems/permAssignmentChange'
20+
21+
components:
22+
securitySchemes:
23+
basicAuth:
24+
type: http
25+
scheme: basic
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: Common Path Items Domain
5+
description: Common Path Items for Back Office REST APIs
6+
version: 1.0.0
7+
components:
8+
pathitems:
9+
permAssignments:
10+
get:
11+
summary: Permanent Assignment Data Creation
12+
responses:
13+
'202':
14+
description: Accepted
15+
content:
16+
application/vnd.api+json:
17+
schema:
18+
"$ref": schemas.yaml#/components/schemas/schemaResponseSuccess
19+
'400':
20+
description: Bad Request
21+
content:
22+
application/vnd.api+json:
23+
schema:
24+
"$ref": schemas.yaml#/components/schemas/schemaResponseError
25+
permAssignmentChange:
26+
get:
27+
summary: Permanent Assignment Data Creation
28+
responses:
29+
'201':
30+
description: Accepted
31+
content:
32+
application/vnd.api+json:
33+
schema:
34+
"$ref": "#/components/schemas/Error"
35+
'404':
36+
description: Accepted
37+
content:
38+
application/vnd.api+json:
39+
schema:
40+
"$ref": "#/components/schemas/RemoteError"
41+
schemas:
42+
Error:
43+
required:
44+
- code
45+
- message
46+
properties:
47+
code:
48+
type: integer
49+
format: int32
50+
message:
51+
type: string
52+
RemoteError:
53+
"$ref": schemas.yaml#/components/schemas/schemaResponseError
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Common Schemas Domain
4+
description: Common Schemas for Back Office REST APIs
5+
version: 1.0.0
6+
components:
7+
schemas:
8+
objectData:
9+
required:
10+
- id
11+
type: object
12+
allOf:
13+
- type: object
14+
properties:
15+
id:
16+
type: string
17+
nullable: true
18+
description: System unique id for the entity in PeopleSoft
19+
objectMetaResponse:
20+
allOf:
21+
- type: object
22+
properties:
23+
boEnvironment:
24+
type: string
25+
minLength: 1
26+
maxLength: 8
27+
example: FNBSA01
28+
boEntityId:
29+
type: string
30+
maxLength: 15
31+
nullable: true
32+
status:
33+
type: string
34+
minLength: 5
35+
enum:
36+
- Error
37+
- Success
38+
example: Error
39+
reQueueFlag:
40+
type: boolean
41+
example: true
42+
default: false
43+
schemaResponseError:
44+
required:
45+
- errors
46+
- jsonapi
47+
- meta
48+
type: object
49+
properties:
50+
meta:
51+
allOf:
52+
- "$ref": "#/components/schemas/objectMetaResponse"
53+
schemaResponseSuccess:
54+
required:
55+
- data
56+
- jsonapi
57+
- meta
58+
type: object
59+
properties:
60+
jsonapi:
61+
meta:
62+
allOf:
63+
- "$ref": "#/components/schemas/objectMetaResponse"
64+
data:
65+
allOf:
66+
- "$ref": "#/components/schemas/objectData"

0 commit comments

Comments
 (0)