Skip to content

Commit aa8b080

Browse files
author
Faron Dutton
committed
Merge branch 'master' into issue721
2 parents 68d8fe1 + 3c9d1d4 commit aa8b080

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

src/main/java/com/networknt/schema/uri/URISchemeFactory.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ public Map<String, URIFactory> getURIFactories() {
4040
return this.uriFactories;
4141
}
4242

43-
private String getScheme(final String uri) {
43+
private static String getScheme(final String uri) {
4444
final Matcher matcher = URI_SCHEME_PATTERN.matcher(uri);
4545
if (matcher.find()) {
4646
return matcher.group(1);
47-
} else {
48-
return null;
4947
}
48+
return null;
5049
}
5150

5251
private URIFactory getFactory(final String scheme) {
@@ -61,8 +60,9 @@ private URIFactory getFactory(final String scheme) {
6160
* @param uri String
6261
* @return URI
6362
*/
63+
@Override
6464
public URI create(final String uri) {
65-
final String scheme = this.getScheme(uri);
65+
final String scheme = getScheme(uri);
6666
if (scheme == null) {
6767
throw new IllegalArgumentException(String.format("Couldn't find URI scheme: %s", uri));
6868
}
@@ -76,22 +76,27 @@ public URI create(final String uri) {
7676
* @param segment URI segment
7777
* @return URI
7878
*/
79+
@Override
7980
public URI create(final URI baseURI, final String segment) {
8081
if (baseURI == null) {
8182
return this.create(segment);
82-
} else {
83-
// We first attempt to get the scheme in case the segment is an absolute URI path.
84-
String scheme = this.getScheme(segment);
85-
if (scheme == null) {
86-
// In this case, the segment is relative to the baseURI.
87-
scheme = baseURI.getScheme();
88-
final URIFactory uriFactory = this.getFactory(scheme);
89-
return uriFactory.create(baseURI, segment);
90-
} else {
91-
// In this case, the segment is an absolute URI path.
92-
final URIFactory uriFactory = this.getFactory(scheme);
93-
return uriFactory.create(segment);
94-
}
9583
}
84+
85+
// We first attempt to get the scheme in case the segment is an absolute URI path.
86+
String scheme = getScheme(segment);
87+
if (scheme == null) {
88+
// In this case, the segment is relative to the baseURI.
89+
scheme = baseURI.getScheme();
90+
final URIFactory uriFactory = this.getFactory(scheme);
91+
return uriFactory.create(baseURI, segment);
92+
}
93+
94+
if ("urn".equals(scheme)) {
95+
return URI.create(segment);
96+
}
97+
98+
// In this case, the segment is an absolute URI path.
99+
final URIFactory uriFactory = this.getFactory(scheme);
100+
return uriFactory.create(segment);
96101
}
97102
}

src/test/java/com/networknt/schema/JsonSchemaTestSuiteTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ private void disableV202012Tests() {
7575
this.disabled.put(Paths.get("src/test/suite/tests/draft2020-12/id.json"), "Unsupported behavior");
7676
this.disabled.put(Paths.get("src/test/suite/tests/draft2020-12/optional/format-assertion.json"), "Unsupported behavior");
7777
this.disabled.put(Paths.get("src/test/suite/tests/draft2020-12/ref.json"), "Unsupported behavior");
78-
this.disabled.put(Paths.get("src/test/suite/tests/draft2020-12/refRemote.json"), "Unsupported behavior");
7978
this.disabled.put(Paths.get("src/test/suite/tests/draft2020-12/vocabulary.json"), "Unsupported behavior");
8079
}
8180

@@ -85,7 +84,6 @@ private void disableV201909Tests() {
8584
this.disabled.put(Paths.get("src/test/suite/tests/draft2019-09/id.json"), "Unsupported behavior");
8685
this.disabled.put(Paths.get("src/test/suite/tests/draft2019-09/recursiveRef.json"), "Unsupported behavior");
8786
this.disabled.put(Paths.get("src/test/suite/tests/draft2019-09/ref.json"), "Unsupported behavior");
88-
this.disabled.put(Paths.get("src/test/suite/tests/draft2019-09/refRemote.json"), "Unsupported behavior");
8987
this.disabled.put(Paths.get("src/test/suite/tests/draft2019-09/vocabulary.json"), "Unsupported behavior");
9088
}
9189

@@ -94,17 +92,14 @@ private void disableV7Tests() {
9492
this.disabled.put(Paths.get("src/test/suite/tests/draft7/defs.json"), "Unsupported behavior");
9593
this.disabled.put(Paths.get("src/test/suite/tests/draft7/optional/content.json"), "Unsupported behavior");
9694
this.disabled.put(Paths.get("src/test/suite/tests/draft7/ref.json"), "Unsupported behavior");
97-
this.disabled.put(Paths.get("src/test/suite/tests/draft7/refRemote.json"), "Unsupported behavior");
9895
}
9996

10097
private void disableV6Tests() {
10198
this.disabled.put(Paths.get("src/test/suite/tests/draft6/ref.json"), "Unsupported behavior");
102-
this.disabled.put(Paths.get("src/test/suite/tests/draft6/refRemote.json"), "Unsupported behavior");
10399
}
104100

105101
private void disableV4Tests() {
106102
this.disabled.put(Paths.get("src/test/suite/tests/draft4/ref.json"), "Unsupported behavior");
107-
this.disabled.put(Paths.get("src/test/suite/tests/draft4/refRemote.json"), "Unsupported behavior");
108103
}
109104

110105
}

src/test/suite/tests/draft2019-09/refRemote.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
}
114114
}
115115
},
116+
"disabled": true,
117+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
116118
"tests": [
117119
{
118120
"description": "number is valid",
@@ -145,6 +147,8 @@
145147
}
146148
}
147149
},
150+
"disabled": true,
151+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
148152
"tests": [
149153
{
150154
"description": "number is valid",
@@ -298,6 +302,8 @@
298302
{
299303
"description": "remote HTTP ref with nested absolute ref",
300304
"schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"},
305+
"disabled": true,
306+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
301307
"tests": [
302308
{
303309
"description": "number is invalid",

src/test/suite/tests/draft2020-12/refRemote.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
}
114114
}
115115
},
116+
"disabled": true,
117+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
116118
"tests": [
117119
{
118120
"description": "number is valid",
@@ -145,6 +147,8 @@
145147
}
146148
}
147149
},
150+
"disabled": true,
151+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
148152
"tests": [
149153
{
150154
"description": "number is valid",
@@ -298,6 +302,8 @@
298302
{
299303
"description": "remote HTTP ref with nested absolute ref",
300304
"schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"},
305+
"disabled": true,
306+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
301307
"tests": [
302308
{
303309
"description": "number is invalid",

src/test/suite/tests/draft4/refRemote.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
}
121121
}
122122
},
123+
"disabled": true,
124+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
123125
"tests": [
124126
{
125127
"description": "number is valid",

src/test/suite/tests/draft6/refRemote.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
}
121121
}
122122
},
123+
"disabled": true,
124+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
123125
"tests": [
124126
{
125127
"description": "number is valid",

src/test/suite/tests/draft7/refRemote.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
}
121121
}
122122
},
123+
"disabled": true,
124+
"reason": "URI resolution does not account for identifiers that are not at the root schema",
123125
"tests": [
124126
{
125127
"description": "number is valid",

0 commit comments

Comments
 (0)