From 0e431c63942e4cb5dfac00c8966ed93c5661c378 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Sun, 24 Dec 2023 14:25:42 -0500 Subject: [PATCH] common compilation_context --- .../jsonschema/common/compilation_context.hpp | 5 --- .../draft201909/schema_parser_impl.hpp | 2 +- .../jsonschema/draft7/schema_parser_impl.hpp | 2 +- .../issues/draft2019-09/issue1.json | 36 ++++++++++++------- .../jsonschema/issues/draft2019-09/issue1.txt | 13 ++----- .../src/jsonschema_draft201909_tests.cpp | 7 +--- 6 files changed, 29 insertions(+), 36 deletions(-) diff --git a/include/jsoncons_ext/jsonschema/common/compilation_context.hpp b/include/jsoncons_ext/jsonschema/common/compilation_context.hpp index 89bcb5a31..7e4eef27d 100644 --- a/include/jsoncons_ext/jsonschema/common/compilation_context.hpp +++ b/include/jsoncons_ext/jsonschema/common/compilation_context.hpp @@ -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) diff --git a/include/jsoncons_ext/jsonschema/draft201909/schema_parser_impl.hpp b/include/jsoncons_ext/jsonschema/draft201909/schema_parser_impl.hpp index df3b83ca9..442e9a496 100644 --- a/include/jsoncons_ext/jsonschema/draft201909/schema_parser_impl.hpp +++ b/include/jsoncons_ext/jsonschema/draft201909/schema_parser_impl.hpp @@ -125,7 +125,7 @@ namespace draft201909 { { schema_location relative(it->value().template as()); 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)); diff --git a/include/jsoncons_ext/jsonschema/draft7/schema_parser_impl.hpp b/include/jsoncons_ext/jsonschema/draft7/schema_parser_impl.hpp index ab6d3f3a4..5122772de 100644 --- a/include/jsoncons_ext/jsonschema/draft7/schema_parser_impl.hpp +++ b/include/jsoncons_ext/jsonschema/draft7/schema_parser_impl.hpp @@ -125,7 +125,7 @@ namespace draft7 { { is_ref = true; schema_location relative(it->value().template as()); - 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)); diff --git a/test/jsonschema/issues/draft2019-09/issue1.json b/test/jsonschema/issues/draft2019-09/issue1.json index 6e12938ee..ca6b6fdd3 100644 --- a/test/jsonschema/issues/draft2019-09/issue1.json +++ b/test/jsonschema/issues/draft2019-09/issue1.json @@ -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 + }*/ ] } ] diff --git a/test/jsonschema/issues/draft2019-09/issue1.txt b/test/jsonschema/issues/draft2019-09/issue1.txt index a9255a14b..7531769b4 100644 --- a/test/jsonschema/issues/draft2019-09/issue1.txt +++ b/test/jsonschema/issues/draft2019-09/issue1.txt @@ -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" diff --git a/test/jsonschema/src/jsonschema_draft201909_tests.cpp b/test/jsonschema/src/jsonschema_draft201909_tests.cpp index 4739a7e2f..893c41025 100644 --- a/test/jsonschema/src/jsonschema_draft201909_tests.cpp +++ b/test/jsonschema/src/jsonschema_draft201909_tests.cpp @@ -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") {