Skip to content

Commit

Permalink
common compilation_context
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 24, 2023
1 parent 4557f5d commit 0e431c6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ namespace jsonschema {
return compilation_context(new_uris);
}

schema_location resolve_back(const schema_location& relative) const
{
return relative.resolve(uris_.back());
}

std::string make_schema_path_with(const std::string& keyword) const
{
for (auto it = uris_.rbegin(); it != uris_.rend(); ++it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace draft201909 {
{
schema_location relative(it->value().template as<std::string>());
is_ref = true;
auto id = context.resolve_back(relative);
auto id = relative.resolve(context.get_base_uri());
auto ref = get_or_create_reference(id);
validator = ref.get();
subschemas_.emplace_back(std::move(ref));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace draft7 {
{
is_ref = true;
schema_location relative(it->value().template as<std::string>());
auto id = context.resolve_back(relative);
auto id = relative.resolve(context.get_base_uri());
auto ref = get_or_create_reference(id);
validator = ref.get();
subschemas_.emplace_back(std::move(ref));
Expand Down
36 changes: 23 additions & 13 deletions test/jsonschema/issues/draft2019-09/issue1.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
[
{
"description": "Location-independent identifier with base URI change in subschema",
"description": "same $anchor with different base uri",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://localhost:1234/draft2019-09/root",
"$ref": "http://localhost:1234/draft2019-09/nested.json#foo",
"$id": "http://localhost:1234/draft2019-09/foobar",
"$defs": {
"A": {
"$id": "nested.json",
"$defs": {
"B": {
"$anchor": "foo",
"type": "integer"
"$id": "child1",
"allOf": [
{
"$id": "child2",
"$anchor": "my_anchor",
"type": "number"
},
{
"$anchor": "my_anchor",
"type": "string"
}
}
]
}
}
},
"$ref": "child1#my_anchor"
},
"tests": [
{
"data": 1,
"description": "match",
"description": "$ref resolves to /$defs/A/allOf/1",
"data": "a",
"valid": true
}
}/*,
{
"description": "$ref does not resolve to /$defs/A/allOf/0",
"data": 1,
"valid": false
}*/
]
}
]
13 changes: 3 additions & 10 deletions test/jsonschema/issues/draft2019-09/issue1.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
./jsonschema/JSON-Schema-Test-Suite/remotes/draft2019-09/nested.json
Could not open ./jsonschema/JSON-Schema-Test-Suite/remotes/child1 for schema loading

"$id": "http://localhost:1234/draft2019-09/root"
"$ref": "http://localhost:1234/draft2019-09/nested.json#foo",


Anchor

"http://localhost:1234/draft2019-09/root"
"http://localhost:1234/draft2019-09/root/nested.json"
"http://localhost:1234/draft2019-09/root/nested.json#foo"
"$id": "http://localhost:1234/draft2019-09/foobar"

"$id": "child1"
7 changes: 1 addition & 6 deletions test/jsonschema/src/jsonschema_draft201909_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ TEST_CASE("jsonschema draft2019-09 tests")
{
SECTION("issues")
{
jsonschema_tests("./jsonschema/issues/draft2019-09/issue1.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue2.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue3.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue4.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue5.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue6.json");
//jsonschema_tests("./jsonschema/issues/draft2019-09/issue1.json");
}
SECTION("tests")
{
Expand Down

0 comments on commit 0e431c6

Please sign in to comment.