Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -214,6 +216,12 @@ protected String merge(String host, String ref) {
}

private String unescapePointer(String jsonPathElement) {
// URL decode the fragment
try {
jsonPathElement = URLDecoder.decode(jsonPathElement, "UTF-8");
} catch (UnsupportedEncodingException e) {
//
}
// Unescape the JSON Pointer segment using the algorithm described in RFC 6901, section 4:
// https://tools.ietf.org/html/rfc6901#section-4
// First transform any occurrence of the sequence '~1' to '/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ public void testIssue289() {
assertNotNull(swagger.getPath("/foo").getGet());
}

@Test
public void testIssue822() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/issue-enc.yaml", null, true);
assertNotNull(result.getSwagger());

Swagger swagger = result.getSwagger();

assertNotNull(swagger.getPath("/foo").getGet());
assertNotNull(swagger.getPath("/bar/wtf").getGet());
assertNull(swagger.getPath("/bar/haha").getGet());
assertNotNull(swagger.getPath("/wtf/{bar}").getGet());
assertNotNull(swagger.getPath("/haha/{bar}").getGet());
assertNull(swagger.getPath("/haha2/{bar}").getGet());

}

@Test
public void testIssue336() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-336.json", null, true);
Expand Down
37 changes: 37 additions & 0 deletions modules/swagger-parser/src/test/resources/issue-enc-b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
swagger: "2.0"

info:
version: 1.0.0
title: Path include test case child

paths:
/foo:
get:
responses:
200:
description: "Request successful"
/bar/wtf:
get:
responses:
200:
description: "Request successful"
/bar/haha:
get:
responses:
200:
description: "Request successful"
/wtf/{bar}:
get:
responses:
200:
description: "Request successful"
/haha/{bar}:
get:
responses:
200:
description: "Request successful"
/haha2/{bar}:
get:
responses:
200:
description: "Request successful"
20 changes: 20 additions & 0 deletions modules/swagger-parser/src/test/resources/issue-enc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
swagger: "2.0"

info:
version: 1.0.0
title: Path include test case

paths:
/foo:
$ref: './issue-enc-b.yaml#/paths/~1foo'
/wtf/{bar}:
$ref: './issue-enc-b.yaml#/paths/~1wtf~1%7Bbar%7D'
/bar/wtf:
$ref: './issue-enc-b.yaml#/paths/~1bar~1wtf'
/haha/{bar}:
$ref: './issue-enc-b.yaml#/paths/~1haha~1{bar}'
/haha2/{bar}:
$ref: './issue-enc-b.yaml#/paths/~1haha/{bar}'
/bar/haha:
$ref: './issue-enc-b.yaml#/paths/bar/haha'