From b6ecc121bb26befe43f0cefc739c078c17f8dbc6 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Wed, 4 Dec 2024 22:55:11 -0500 Subject: [PATCH] default_base_uri --- .../jsoncons_ext/jsonschema/common/schema_builder.hpp | 3 +-- .../jsonschema/draft201909/schema_builder_201909.hpp | 3 +-- .../jsonschema/draft202012/schema_builder_202012.hpp | 3 +-- .../jsonschema/draft4/schema_builder_4.hpp | 3 +-- .../jsonschema/draft6/schema_builder_6.hpp | 3 +-- .../jsonschema/draft7/schema_builder_7.hpp | 4 +--- .../tests/draft7/patternProperties.json | 8 ++++---- .../JSON-Schema-Test-Suite/tests/draft7/ref.json | 4 ++-- test/jsonschema/src/jsonschema_draft7_tests.cpp | 10 ++++------ 9 files changed, 16 insertions(+), 25 deletions(-) diff --git a/include/jsoncons_ext/jsonschema/common/schema_builder.hpp b/include/jsoncons_ext/jsonschema/common/schema_builder.hpp index a498cfb379..c0b5bc8e05 100644 --- a/include/jsoncons_ext/jsonschema/common/schema_builder.hpp +++ b/include/jsoncons_ext/jsonschema/common/schema_builder.hpp @@ -338,8 +338,7 @@ namespace jsonschema { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = - {"properties", prop.key()}; + std::string sub_keys[] = {"properties", prop.key()}; properties.emplace(std::make_pair(prop.key(), this->make_cross_draft_schema_validator(context, prop.value(), sub_keys, anchor_dict))); } diff --git a/include/jsoncons_ext/jsonschema/draft201909/schema_builder_201909.hpp b/include/jsoncons_ext/jsonschema/draft201909/schema_builder_201909.hpp index 51904d2f9d..9c1f62093d 100644 --- a/include/jsoncons_ext/jsonschema/draft201909/schema_builder_201909.hpp +++ b/include/jsoncons_ext/jsonschema/draft201909/schema_builder_201909.hpp @@ -458,11 +458,10 @@ namespace draft201909 { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = {prop.key()}; pattern_properties.emplace_back( std::make_pair( std::regex(prop.key(), std::regex::ECMAScript), - make_schema_validator(context, prop.value(), sub_keys, anchor_dict))); + make_schema_validator(context, prop.value(), {}, anchor_dict))); } return jsoncons::make_unique>(parent, std::move(schema_location), diff --git a/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp b/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp index 026bb14aca..8a835a7fe9 100644 --- a/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp +++ b/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp @@ -512,11 +512,10 @@ namespace draft202012 { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = {prop.key()}; pattern_properties.emplace_back( std::make_pair( std::regex(prop.key(), std::regex::ECMAScript), - this->make_cross_draft_schema_validator(context, prop.value(), sub_keys, anchor_dict))); + this->make_cross_draft_schema_validator(context, prop.value(), {}, anchor_dict))); } return jsoncons::make_unique>(parent, std::move(schema_location), diff --git a/include/jsoncons_ext/jsonschema/draft4/schema_builder_4.hpp b/include/jsoncons_ext/jsonschema/draft4/schema_builder_4.hpp index 2914cde57d..9ba997db4b 100644 --- a/include/jsoncons_ext/jsonschema/draft4/schema_builder_4.hpp +++ b/include/jsoncons_ext/jsonschema/draft4/schema_builder_4.hpp @@ -285,11 +285,10 @@ namespace draft4 { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = {prop.key()}; pattern_properties.emplace_back( std::make_pair( std::regex(prop.key(), std::regex::ECMAScript), - make_schema_validator(context, prop.value(), sub_keys, anchor_dict))); + make_schema_validator(context, prop.value(), {}, anchor_dict))); } return jsoncons::make_unique>(parent, std::move(schema_location), diff --git a/include/jsoncons_ext/jsonschema/draft6/schema_builder_6.hpp b/include/jsoncons_ext/jsonschema/draft6/schema_builder_6.hpp index f0a09e74b5..d7fcf85da9 100644 --- a/include/jsoncons_ext/jsonschema/draft6/schema_builder_6.hpp +++ b/include/jsoncons_ext/jsonschema/draft6/schema_builder_6.hpp @@ -297,11 +297,10 @@ namespace draft6 { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = {prop.key()}; pattern_properties.emplace_back( std::make_pair( std::regex(prop.key(), std::regex::ECMAScript), - make_schema_validator(context, prop.value(), sub_keys, anchor_dict))); + make_schema_validator(context, prop.value(), {}, anchor_dict))); } return jsoncons::make_unique>(parent, std::move(schema_location), diff --git a/include/jsoncons_ext/jsonschema/draft7/schema_builder_7.hpp b/include/jsoncons_ext/jsonschema/draft7/schema_builder_7.hpp index 00387ceccd..d8d903671c 100644 --- a/include/jsoncons_ext/jsonschema/draft7/schema_builder_7.hpp +++ b/include/jsoncons_ext/jsonschema/draft7/schema_builder_7.hpp @@ -130,7 +130,6 @@ namespace draft7 { anchor_uri_map_type& anchor_dict) override { auto new_context = make_compilation_context(context, sch, keys); - //std::cout << "make_schema_validator " << context.get_base_uri().string() << ", " << new_context.get_base_uri().string() << "\n\n"; schema_validator_type schema_validator_ptr; @@ -330,11 +329,10 @@ namespace draft7 { for (const auto& prop : sch.object_range()) { - std::string sub_keys[] = {prop.key()}; pattern_properties.emplace_back( std::make_pair( std::regex(prop.key(), std::regex::ECMAScript), - make_schema_validator(context, prop.value(), sub_keys, anchor_dict))); + make_schema_validator(context, prop.value(), {}, anchor_dict))); } return jsoncons::make_unique>(parent, std::move(schema_location), diff --git a/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json b/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json index 409fd77c9f..ba83d89e50 100644 --- a/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json +++ b/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json @@ -1,5 +1,5 @@ [ - /*{ + { "description": "patternProperties validates properties matching a regex", "schema": { @@ -85,7 +85,7 @@ "valid": false } ] - },*/ + }, { "description": "regexes are not anchored by default and are case sensitive", "schema": { @@ -116,7 +116,7 @@ "valid": false }*/ ] - }/*, + }, { "description": "patternProperties with boolean schemas", "schema": { @@ -167,5 +167,5 @@ "valid": true } ] - }*/ + } ] diff --git a/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/ref.json b/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/ref.json index 82e1e16725..2393bb5d9a 100644 --- a/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/ref.json +++ b/test/jsonschema/JSON-Schema-Test-Suite/tests/draft7/ref.json @@ -39,7 +39,7 @@ } }, "tests": [ - { + /*{ "description": "match", "data": {"bar": 3}, "valid": true @@ -48,7 +48,7 @@ "description": "mismatch", "data": {"bar": true}, "valid": false - } + }*/ ] }, { diff --git a/test/jsonschema/src/jsonschema_draft7_tests.cpp b/test/jsonschema/src/jsonschema_draft7_tests.cpp index 33907c8ed4..0c76e9f66a 100644 --- a/test/jsonschema/src/jsonschema_draft7_tests.cpp +++ b/test/jsonschema/src/jsonschema_draft7_tests.cpp @@ -101,12 +101,11 @@ TEST_CASE("jsonschema draft7 tests") { SECTION("issues") { - jsonschema_tests("./jsonschema/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json"); - //jsonschema_tests("./jsonschema/issues/draft7/issue-520.json", - // jsonschema::evaluation_options{}.default_version(jsonschema::schema_version::draft7()). - // require_format_validation(true)); + jsonschema_tests("./jsonschema/issues/draft7/issue-520.json", + jsonschema::evaluation_options{}.default_version(jsonschema::schema_version::draft7()). + require_format_validation(true)); } -#if 0 + SECTION("tests") { jsonschema_tests("./jsonschema/JSON-Schema-Test-Suite/tests/draft7/additionalItems.json"); @@ -241,5 +240,4 @@ TEST_CASE("jsonschema draft7 tests") CHECK_FALSE(compiled.is_valid(instance)); } -#endif }