Skip to content

Commit 6373def

Browse files
committed
fix for #260 with integration test
1 parent 6ed56f9 commit 6373def

File tree

7 files changed

+65
-5
lines changed

7 files changed

+65
-5
lines changed

core/src/main/java/org/everit/json/schema/loader/JsonPointerEvaluator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.io.InputStreamReader;
1111
import java.io.UncheckedIOException;
1212
import java.io.UnsupportedEncodingException;
13+
import java.net.URI;
14+
import java.net.URISyntaxException;
1315
import java.net.URLDecoder;
1416
import java.nio.charset.Charset;
1517
import java.util.LinkedList;
@@ -106,8 +108,13 @@ static final JsonPointerEvaluator forDocument(JsonObject document, String fragme
106108
return new JsonPointerEvaluator(() -> document, fragment);
107109
}
108110

109-
private static JsonObject configureBasedOnState(JsonObject obj, LoadingState callingState) {
110-
obj.ls = new LoadingState(callingState.config, callingState.pointerSchemas, obj, obj, null, SchemaLocation.empty());
111+
private static JsonObject configureBasedOnState(JsonObject obj, LoadingState callingState, String id) {
112+
try {
113+
URI uri = new URI(id);
114+
obj.ls = new LoadingState(callingState.config, callingState.pointerSchemas, obj, obj, uri, SchemaLocation.empty());
115+
} catch (URISyntaxException e) {
116+
throw callingState.createSchemaException("invalid URI: " + e.getMessage());
117+
}
111118
return obj;
112119
}
113120

@@ -122,7 +129,8 @@ static final JsonPointerEvaluator forURL(SchemaClient schemaClient, String url,
122129
fragment = url.substring(poundIdx);
123130
toBeQueried = url.substring(0, poundIdx);
124131
}
125-
return new JsonPointerEvaluator(() -> configureBasedOnState(executeWith(schemaClient, toBeQueried), callingState), fragment);
132+
return new JsonPointerEvaluator(() -> configureBasedOnState(executeWith(schemaClient, toBeQueried), callingState, toBeQueried),
133+
fragment);
126134
}
127135

128136
private final Supplier<JsonObject> documentProvider;

core/src/main/java/org/everit/json/schema/loader/ReferenceLookup.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
160160
ls.pointerSchemas.put(absPointerString, refBuilder);
161161
JsonPointerEvaluator.QueryResult result = pointer.query();
162162

163+
URI resolutionScope = !isInternal ? withoutFragment(absPointerString) : ls.id;
164+
JsonObject containingDocument = result.getContainingDocument();
163165
SchemaLoader childLoader = ls.initChildLoader()
164166
.pointerToCurrentObj(SchemaLocation.parseURI(absPointerString))
165-
.resolutionScope(!isInternal ? withoutFragment(absPointerString) : ls.id)
167+
.resolutionScope(resolutionScope)
166168
.schemaJson(result.getQueryResult())
167-
.rootSchemaJson(result.getContainingDocument()).build();
169+
.rootSchemaJson(containingDocument).build();
168170
Schema referredSchema = childLoader.load().build();
169171
refBuilder.schemaLocation(SchemaLocation.parseURI(absPointerString));
170172
refBuilder.build().setReferredSchema(referredSchema);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"house": {
3+
"type": "object",
4+
"properties": {
5+
"rooms": {
6+
"type": "array",
7+
"items": {
8+
"$ref": "#/room"
9+
}
10+
}
11+
}
12+
},
13+
"room": {
14+
"type": "object",
15+
"properties": {
16+
"door": {
17+
"$ref": "stuff.json#/door"
18+
}
19+
}
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"door": {
3+
"type": "object",
4+
"properties": {
5+
"material": { "type": "string" }
6+
}
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "http://localhost:1234/",
4+
"type": "object",
5+
"properties": {
6+
"house": {
7+
"$ref": "example/definitions/buildings.json#/house"
8+
}
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"house": {
3+
"rooms": [ {
4+
"door": { "material": 1 }
5+
}]
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"metaSchemaVersion": 7
3+
}
4+

0 commit comments

Comments
 (0)