Skip to content

Commit 993c3f7

Browse files
committed
fixing #333 - mapping resolutionScope to root schema location
1 parent 721c1bc commit 993c3f7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
176176
JsonObject containingDocument = result.getContainingDocument();
177177
SchemaLocation resultLocation = result.getQueryResult().ls.pointerToCurrentObj;
178178
SchemaLoader childLoader = ls.initNewDocumentLoader()
179-
.pointerToCurrentObj(resultLocation)
180179
.resolutionScope(resolutionScope)
180+
.pointerToCurrentObj(resultLocation)
181181
.schemaJson(result.getQueryResult())
182182
.rootSchemaJson(containingDocument).build();
183183
Schema referredSchema = childLoader.load().build();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public SchemaLoaderBuilder resolutionScope(String id) {
195195

196196
public SchemaLoaderBuilder resolutionScope(URI id) {
197197
this.id = id;
198+
this.pointerToCurrentObj = new SchemaLocation(id, emptyList());
198199
return this;
199200
}
200201

core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.everit.json.schema.loader;
22

33
import static java.util.Arrays.asList;
4+
import static java.util.Collections.emptyList;
45
import static java.util.Collections.emptyMap;
56
import static org.everit.json.schema.JSONMatcher.sameJsonAs;
67
import static org.everit.json.schema.TestSupport.asStream;
@@ -20,6 +21,8 @@
2021

2122
import java.io.ByteArrayInputStream;
2223
import java.io.InputStream;
24+
import java.net.URI;
25+
import java.net.URISyntaxException;
2326
import java.util.HashMap;
2427
import java.util.HashSet;
2528
import java.util.Map;
@@ -41,6 +44,7 @@
4144
import org.everit.json.schema.ResourceLoader;
4245
import org.everit.json.schema.Schema;
4346
import org.everit.json.schema.SchemaException;
47+
import org.everit.json.schema.SchemaLocation;
4448
import org.everit.json.schema.StringSchema;
4549
import org.everit.json.schema.TestSupport;
4650
import org.everit.json.schema.TrueSchema;
@@ -811,4 +815,14 @@ public void httpsSchemaURI() {
811815
}
812816

813817
private class CustomDateTimeFormatValidator extends DateTimeFormatValidator {}
818+
819+
@Test
820+
public void explicitlySetResolutionScope_isMappedToSchemaLocation() throws URISyntaxException {
821+
Schema actual = SchemaLoader.builder()
822+
.resolutionScope("http://example.org")
823+
.schemaJson(new JSONObject("{}"))
824+
.build().load().build();
825+
assertEquals(new SchemaLocation(new URI("http://example.org"), emptyList()), actual.getLocation());
826+
}
827+
814828
}

0 commit comments

Comments
 (0)