Skip to content

Commit

Permalink
fix for #260 with integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
erosb committed Jan 19, 2019
1 parent 6ed56f9 commit 6373def
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.LinkedList;
Expand Down Expand Up @@ -106,8 +108,13 @@ static final JsonPointerEvaluator forDocument(JsonObject document, String fragme
return new JsonPointerEvaluator(() -> document, fragment);
}

private static JsonObject configureBasedOnState(JsonObject obj, LoadingState callingState) {
obj.ls = new LoadingState(callingState.config, callingState.pointerSchemas, obj, obj, null, SchemaLocation.empty());
private static JsonObject configureBasedOnState(JsonObject obj, LoadingState callingState, String id) {
try {
URI uri = new URI(id);
obj.ls = new LoadingState(callingState.config, callingState.pointerSchemas, obj, obj, uri, SchemaLocation.empty());
} catch (URISyntaxException e) {
throw callingState.createSchemaException("invalid URI: " + e.getMessage());
}
return obj;
}

Expand All @@ -122,7 +129,8 @@ static final JsonPointerEvaluator forURL(SchemaClient schemaClient, String url,
fragment = url.substring(poundIdx);
toBeQueried = url.substring(0, poundIdx);
}
return new JsonPointerEvaluator(() -> configureBasedOnState(executeWith(schemaClient, toBeQueried), callingState), fragment);
return new JsonPointerEvaluator(() -> configureBasedOnState(executeWith(schemaClient, toBeQueried), callingState, toBeQueried),
fragment);
}

private final Supplier<JsonObject> documentProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
ls.pointerSchemas.put(absPointerString, refBuilder);
JsonPointerEvaluator.QueryResult result = pointer.query();

URI resolutionScope = !isInternal ? withoutFragment(absPointerString) : ls.id;
JsonObject containingDocument = result.getContainingDocument();
SchemaLoader childLoader = ls.initChildLoader()
.pointerToCurrentObj(SchemaLocation.parseURI(absPointerString))
.resolutionScope(!isInternal ? withoutFragment(absPointerString) : ls.id)
.resolutionScope(resolutionScope)
.schemaJson(result.getQueryResult())
.rootSchemaJson(result.getContainingDocument()).build();
.rootSchemaJson(containingDocument).build();
Schema referredSchema = childLoader.load().build();
refBuilder.schemaLocation(SchemaLocation.parseURI(absPointerString));
refBuilder.build().setReferredSchema(referredSchema);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"house": {
"type": "object",
"properties": {
"rooms": {
"type": "array",
"items": {
"$ref": "#/room"
}
}
}
},
"room": {
"type": "object",
"properties": {
"door": {
"$ref": "stuff.json#/door"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"door": {
"type": "object",
"properties": {
"material": { "type": "string" }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://localhost:1234/",
"type": "object",
"properties": {
"house": {
"$ref": "example/definitions/buildings.json#/house"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"house": {
"rooms": [ {
"door": { "material": 1 }
}]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metaSchemaVersion": 7
}

0 comments on commit 6373def

Please sign in to comment.