Skip to content

Commit 9f67c68

Browse files
committed
Issue with resolving a external $ref in a subfolder.
I have a ref like $ref: './subfolder/domain.yaml#/components/responses/ErrorRespons When resolving I get the following error Unable to load RELATIVE ref: ./subfolder/subfolder/domain.yaml Note the double ./subfolder/subfolder!
1 parent 585773c commit 9f67c68

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

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
@@ -1323,6 +1323,17 @@ public void testIssue360() {
13231323
assertEquals(refModel.get$ref(), "#/components/schemas/Pet");
13241324
}
13251325

1326+
@Test
1327+
public void testRelativePath() {
1328+
OpenAPIV3Parser parser = new OpenAPIV3Parser();
1329+
ParseOptions options = new ParseOptions();
1330+
options.setResolve(true);
1331+
SwaggerParseResult readResult = parser.readLocation("src/test/resources/relative-issue/api.yaml", null, options);
1332+
if (readResult.getMessages().size() > 0) {
1333+
fail(Json.pretty(readResult.getMessages()));
1334+
}
1335+
}
1336+
13261337
private OpenAPI doRelativeFileTest(String location) {
13271338
OpenAPIV3Parser parser = new OpenAPIV3Parser();
13281339
ParseOptions options = new ParseOptions();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.0
2+
info:
3+
version: '0.0.1'
4+
title: 'Parser debug'
5+
description: 'Parser debug'
6+
paths:
7+
/scans:
8+
get:
9+
responses:
10+
200:
11+
description: Yay
12+
500:
13+
$ref: './subfolder/domain.yaml#/components/responses/ErrorResponse'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
openapi: 3.0.0
2+
3+
info:
4+
title: My domain
5+
description: My domain
6+
version: '0.0.1'
7+
8+
paths: {}
9+
10+
components:
11+
responses:
12+
ErrorResponse:
13+
description: An error has occurred
14+
content:
15+
application/json:
16+
schema:
17+
$ref: '#/components/schemas/ErrorMessage'
18+
schemas:
19+
ErrorMessage:
20+
type: object
21+
required:
22+
- timestamp
23+
- path
24+
- status
25+
properties:
26+
timestamp:
27+
description: The timestamp of when the error occurred
28+
type: string
29+
format: date-time
30+
path:
31+
description: Requested path
32+
type: string
33+
status:
34+
description: HTTP status code
35+
type: integer
36+
error:
37+
description: HTTP response phrase
38+
type: string
39+
message:
40+
description: Error message
41+
type: string
42+
requestId:
43+
description: Internal request id
44+
type: string
45+
errors:
46+
description: Detailed error descriptions
47+
type: array
48+
items:
49+
type: object

0 commit comments

Comments
 (0)