Skip to content

Commit b7e384d

Browse files
committed
refs #822 - decode properly refs
1 parent 94fd427 commit b7e384d

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.apache.commons.lang3.StringUtils;
1616

1717
import java.io.File;
18+
import java.io.UnsupportedEncodingException;
19+
import java.net.URLDecoder;
1820
import java.nio.file.Path;
1921
import java.util.Collections;
2022
import java.util.HashMap;
@@ -249,6 +251,12 @@ else if(ref.startsWith("#/components/securitySchemes")) {
249251
}
250252

251253
private String unescapePointer(String jsonPathElement) {
254+
// URL decode the fragment
255+
try {
256+
jsonPathElement = URLDecoder.decode(jsonPathElement, "UTF-8");
257+
} catch (UnsupportedEncodingException e) {
258+
//
259+
}
252260
// Unescape the JSON Pointer segment using the algorithm described in RFC 6901, section 4:
253261
// https://tools.ietf.org/html/rfc6901#section-4
254262
// First transform any occurrence of the sequence '~1' to '/'

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ public void testIssue289() {
152152
assertNotNull(swagger.getPaths().get("/foo").getGet());
153153
}
154154

155+
@Test
156+
public void testIssue822() {
157+
158+
ParseOptions options = new ParseOptions();
159+
options.setResolve(true);
160+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/issue-822.yaml", null, options);
161+
162+
OpenAPI swagger = result.getOpenAPI();
163+
assertNotNull(swagger.getPaths().get("/foo").getGet());
164+
assertNotNull(swagger.getPaths().get("/bar/wtf").getGet());
165+
assertNull(swagger.getPaths().get("/bar/haha").getGet());
166+
assertNotNull(swagger.getPaths().get("/wtf/{bar}").getGet());
167+
assertNotNull(swagger.getPaths().get("/haha/{bar}").getGet());
168+
assertNull(swagger.getPaths().get("/haha2/{bar}").getGet());
169+
}
170+
155171
@Test
156172
public void testIssue336() {
157173
ParseOptions options = new ParseOptions();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: "3.0.0"
2+
3+
info:
4+
version: 1.0.0
5+
title: Path include test case child
6+
7+
paths:
8+
/foo:
9+
get:
10+
responses:
11+
200:
12+
description: "Request successful"
13+
/bar/wtf:
14+
get:
15+
responses:
16+
200:
17+
description: "Request successful"
18+
/bar/haha:
19+
get:
20+
responses:
21+
200:
22+
description: "Request successful"
23+
/wtf/{bar}:
24+
get:
25+
responses:
26+
200:
27+
description: "Request successful"
28+
/haha/{bar}:
29+
get:
30+
responses:
31+
200:
32+
description: "Request successful"
33+
/haha2/{bar}:
34+
get:
35+
responses:
36+
200:
37+
description: "Request successful"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
openapi: "3.0.0"
2+
3+
info:
4+
version: 1.0.0
5+
title: Path include test case
6+
7+
paths:
8+
/foo:
9+
$ref: './issue-822-b.yaml#/paths/~1foo'
10+
/wtf/{bar}:
11+
$ref: './issue-822-b.yaml#/paths/~1wtf~1%7Bbar%7D'
12+
/bar/wtf:
13+
$ref: './issue-822-b.yaml#/paths/~1bar~1wtf'
14+
/haha/{bar}:
15+
$ref: './issue-822-b.yaml#/paths/~1haha~1{bar}'
16+
/haha2/{bar}:
17+
$ref: './issue-822-b.yaml#/paths/~1haha/{bar}'
18+
/bar/haha:
19+
$ref: './issue-822-b.yaml#/paths/bar/haha'

0 commit comments

Comments
 (0)