From 1ea4479517052693b74cb2aacee7943f22e1f500 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 24 Dec 2024 19:08:03 -0400 Subject: [PATCH] Mark in-place applicators with special rules as `ApplicatorValueOther` (#1405) Signed-off-by: Juan Cruz Viotti --- src/jsonschema/default_walker.cc | 20 +++++++++---------- .../jsontoolkit/jsonschema_walker.h | 4 ++++ src/jsonschema/walker.cc | 2 ++ .../jsonschema_default_walker_2019_09_test.cc | 6 +++--- .../jsonschema_default_walker_2020_12_test.cc | 6 +++--- .../jsonschema_default_walker_draft4_test.cc | 2 +- .../jsonschema_default_walker_draft6_test.cc | 2 +- .../jsonschema_default_walker_draft7_test.cc | 4 ++-- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/jsonschema/default_walker.cc b/src/jsonschema/default_walker.cc index 7b243f076..768b5cca8 100644 --- a/src/jsonschema/default_walker.cc +++ b/src/jsonschema/default_walker.cc @@ -37,12 +37,12 @@ auto sourcemeta::jsontoolkit::default_schema_walker( ApplicatorElementsInPlace) WALK(HTTPS_BASE "2020-12/vocab/applicator", "allOf", ApplicatorElementsInPlace) - WALK(HTTPS_BASE "2020-12/vocab/applicator", "if", ApplicatorValueInPlace) + WALK(HTTPS_BASE "2020-12/vocab/applicator", "if", ApplicatorValueOther) WALK(HTTPS_BASE "2020-12/vocab/applicator", "then", ApplicatorValueInPlace, "if") WALK(HTTPS_BASE "2020-12/vocab/applicator", "else", ApplicatorValueInPlace, "if") - WALK(HTTPS_BASE "2020-12/vocab/applicator", "not", ApplicatorValueInPlace) + WALK(HTTPS_BASE "2020-12/vocab/applicator", "not", ApplicatorValueOther) // For the purpose of compiler optimizations WALK_MAYBE_DEPENDENT(HTTPS_BASE "2020-12/vocab/applicator", "properties", ApplicatorMembers, HTTPS_BASE "2020-12/vocab/validation", @@ -100,7 +100,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker( HTTPS_BASE "2020-12/vocab/applicator", "prefixItems", "items", "contains") WALK(HTTPS_BASE "2020-12/vocab/content", "contentSchema", - ApplicatorValueInPlace) + ApplicatorValueOther) WALK(HTTPS_BASE "2020-12/vocab/content", "contentMediaType", Annotation) WALK(HTTPS_BASE "2020-12/vocab/content", "contentEncoding", Annotation) WALK(HTTPS_BASE "2020-12/vocab/format-assertion", "format", Assertion) @@ -124,12 +124,12 @@ auto sourcemeta::jsontoolkit::default_schema_walker( ApplicatorElementsInPlace) WALK(HTTPS_BASE "2019-09/vocab/applicator", "oneOf", ApplicatorElementsInPlace) - WALK(HTTPS_BASE "2019-09/vocab/applicator", "if", ApplicatorValueInPlace) + WALK(HTTPS_BASE "2019-09/vocab/applicator", "if", ApplicatorValueOther) WALK(HTTPS_BASE "2019-09/vocab/applicator", "then", ApplicatorValueInPlace, "if") WALK(HTTPS_BASE "2019-09/vocab/applicator", "else", ApplicatorValueInPlace, "if") - WALK(HTTPS_BASE "2019-09/vocab/applicator", "not", ApplicatorValueInPlace) + WALK(HTTPS_BASE "2019-09/vocab/applicator", "not", ApplicatorValueOther) // For the purpose of compiler optimizations WALK_MAYBE_DEPENDENT(HTTPS_BASE "2019-09/vocab/applicator", "properties", ApplicatorMembers, HTTPS_BASE "2019-09/vocab/validation", @@ -185,7 +185,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker( WALK(HTTPS_BASE "2019-09/vocab/meta-data", "default", Annotation) WALK(HTTPS_BASE "2019-09/vocab/format", "format", Annotation) WALK(HTTPS_BASE "2019-09/vocab/content", "contentSchema", - ApplicatorValueInPlace) + ApplicatorValueOther) WALK(HTTPS_BASE "2019-09/vocab/content", "contentMediaType", Annotation) WALK(HTTPS_BASE "2019-09/vocab/content", "contentEncoding", Annotation) WALK(HTTPS_BASE "2019-09/vocab/hyper-schema", "hrefSchema", ApplicatorValue) @@ -234,13 +234,13 @@ auto sourcemeta::jsontoolkit::default_schema_walker( WALK(HTTP_BASE "draft-07/schema#", "dependencies", ApplicatorMembers, "$ref") WALK(HTTP_BASE "draft-07/schema#", "propertyNames", ApplicatorValueInPlace, "$ref") - WALK(HTTP_BASE "draft-07/schema#", "if", ApplicatorValueInPlace, "$ref") + WALK(HTTP_BASE "draft-07/schema#", "if", ApplicatorValueOther, "$ref") WALK(HTTP_BASE "draft-07/schema#", "then", ApplicatorValueInPlace, "if") WALK(HTTP_BASE "draft-07/schema#", "else", ApplicatorValueInPlace, "if") WALK(HTTP_BASE "draft-07/schema#", "allOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-07/schema#", "anyOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-07/schema#", "oneOf", ApplicatorElementsInPlace, "$ref") - WALK(HTTP_BASE "draft-07/schema#", "not", ApplicatorValueInPlace, "$ref") + WALK(HTTP_BASE "draft-07/schema#", "not", ApplicatorValueOther, "$ref") WALK(HTTP_BASE "draft-07/schema#", "format", Other, "$ref") WALK(HTTP_BASE "draft-07/schema#", "contentEncoding", Other, "$ref") WALK(HTTP_BASE "draft-07/schema#", "contentMediaType", Other, "$ref") @@ -308,7 +308,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker( WALK(HTTP_BASE "draft-06/schema#", "allOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-06/schema#", "anyOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-06/schema#", "oneOf", ApplicatorElementsInPlace, "$ref") - WALK(HTTP_BASE "draft-06/schema#", "not", ApplicatorValueInPlace, "$ref") + WALK(HTTP_BASE "draft-06/schema#", "not", ApplicatorValueOther, "$ref") WALK(HTTP_BASE "draft-06/schema#", "format", Other, "$ref") WALK(HTTP_BASE "draft-06/schema#", "contentEncoding", Other, "$ref") WALK(HTTP_BASE "draft-06/schema#", "contentMediaType", Other, "$ref") @@ -369,7 +369,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker( WALK(HTTP_BASE "draft-04/schema#", "allOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-04/schema#", "anyOf", ApplicatorElementsInPlace, "$ref") WALK(HTTP_BASE "draft-04/schema#", "oneOf", ApplicatorElementsInPlace, "$ref") - WALK(HTTP_BASE "draft-04/schema#", "not", ApplicatorValueInPlace, "$ref") + WALK(HTTP_BASE "draft-04/schema#", "not", ApplicatorValueOther, "$ref") WALK(HTTP_BASE "draft-04/schema#", "format", Other, "$ref") WALK(HTTP_BASE "draft-04/schema#", "definitions", LocationMembers, "$ref") WALK(HTTP_BASE "draft-04/schema#", "title", Other, "$ref") diff --git a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_walker.h b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_walker.h index 82dfa74c9..bd1ca7849 100644 --- a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_walker.h +++ b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_walker.h @@ -44,6 +44,10 @@ enum class SchemaWalkerStrategy : std::uint8_t { /// takes a JSON Schema definition as an argument ApplicatorValue, /// The JSON Schema keyword is an applicator that potentially + /// takes a JSON Schema definition as an argument but its evaluation follows + /// special rules + ApplicatorValueOther, + /// The JSON Schema keyword is an applicator that potentially /// takes a JSON Schema definition as an argument without affecting the /// instance location ApplicatorValueInPlace, diff --git a/src/jsonschema/walker.cc b/src/jsonschema/walker.cc index a85a13c61..44b2f58a3 100644 --- a/src/jsonschema/walker.cc +++ b/src/jsonschema/walker.cc @@ -64,6 +64,8 @@ auto walk(sourcemeta::jsontoolkit::Pointer &pointer, switch (walker(pair.first, vocabularies).strategy) { case sourcemeta::jsontoolkit::SchemaWalkerStrategy::ApplicatorValue: [[fallthrough]]; + case sourcemeta::jsontoolkit::SchemaWalkerStrategy::ApplicatorValueOther: + [[fallthrough]]; case sourcemeta::jsontoolkit::SchemaWalkerStrategy:: ApplicatorValueInPlace: { sourcemeta::jsontoolkit::Pointer new_pointer{pointer}; diff --git a/test/jsonschema/jsonschema_default_walker_2019_09_test.cc b/test/jsonschema/jsonschema_default_walker_2019_09_test.cc index f28fe940d..62a075bd0 100644 --- a/test/jsonschema/jsonschema_default_walker_2019_09_test.cc +++ b/test/jsonschema/jsonschema_default_walker_2019_09_test.cc @@ -163,7 +163,7 @@ TEST(JSONSchema_default_walker_2019_09, applicator_not) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("not", VOCABULARIES_2019_09_APPLICATOR)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2019-09/vocab/applicator"); @@ -174,7 +174,7 @@ TEST(JSONSchema_default_walker_2019_09, applicator_if) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("if", VOCABULARIES_2019_09_APPLICATOR)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2019-09/vocab/applicator"); @@ -597,7 +597,7 @@ TEST(JSONSchema_default_walker_2019_09, content_contentSchema) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("contentSchema", VOCABULARIES_2019_09_CONTENT)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2019-09/vocab/content"); diff --git a/test/jsonschema/jsonschema_default_walker_2020_12_test.cc b/test/jsonschema/jsonschema_default_walker_2020_12_test.cc index 6b13ec1e1..9d3abf3af 100644 --- a/test/jsonschema/jsonschema_default_walker_2020_12_test.cc +++ b/test/jsonschema/jsonschema_default_walker_2020_12_test.cc @@ -171,7 +171,7 @@ TEST(JSONSchema_default_walker_2020_12, applicator_not) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("not", VOCABULARIES_2020_12_APPLICATOR)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2020-12/vocab/applicator"); @@ -182,7 +182,7 @@ TEST(JSONSchema_default_walker_2020_12, applicator_if) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("if", VOCABULARIES_2020_12_APPLICATOR)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2020-12/vocab/applicator"); @@ -654,7 +654,7 @@ TEST(JSONSchema_default_walker_2020_12, content_contentSchema) { using namespace sourcemeta::jsontoolkit; const auto result{ default_schema_walker("contentSchema", VOCABULARIES_2020_12_CONTENT)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "https://json-schema.org/draft/2020-12/vocab/content"); diff --git a/test/jsonschema/jsonschema_default_walker_draft4_test.cc b/test/jsonschema/jsonschema_default_walker_draft4_test.cc index 370d372ff..226cb3ec9 100644 --- a/test/jsonschema/jsonschema_default_walker_draft4_test.cc +++ b/test/jsonschema/jsonschema_default_walker_draft4_test.cc @@ -86,7 +86,7 @@ TEST(JSONSchema_default_walker_draft4, oneOf) { TEST(JSONSchema_default_walker_draft4, not) { using namespace sourcemeta::jsontoolkit; const auto result{default_schema_walker("not", VOCABULARIES_DRAFT4)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "http://json-schema.org/draft-04/schema#"); diff --git a/test/jsonschema/jsonschema_default_walker_draft6_test.cc b/test/jsonschema/jsonschema_default_walker_draft6_test.cc index 5123677db..306760105 100644 --- a/test/jsonschema/jsonschema_default_walker_draft6_test.cc +++ b/test/jsonschema/jsonschema_default_walker_draft6_test.cc @@ -86,7 +86,7 @@ TEST(JSONSchema_default_walker_draft6, oneOf) { TEST(JSONSchema_default_walker_draft6, not) { using namespace sourcemeta::jsontoolkit; const auto result{default_schema_walker("not", VOCABULARIES_DRAFT6)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "http://json-schema.org/draft-06/schema#"); diff --git a/test/jsonschema/jsonschema_default_walker_draft7_test.cc b/test/jsonschema/jsonschema_default_walker_draft7_test.cc index 9dba141c4..7808de580 100644 --- a/test/jsonschema/jsonschema_default_walker_draft7_test.cc +++ b/test/jsonschema/jsonschema_default_walker_draft7_test.cc @@ -97,7 +97,7 @@ TEST(JSONSchema_default_walker_draft7, oneOf) { TEST(JSONSchema_default_walker_draft7, not) { using namespace sourcemeta::jsontoolkit; const auto result{default_schema_walker("not", VOCABULARIES_DRAFT7)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "http://json-schema.org/draft-07/schema#"); @@ -108,7 +108,7 @@ TEST(JSONSchema_default_walker_draft7, not) { TEST(JSONSchema_default_walker_draft7, if) { using namespace sourcemeta::jsontoolkit; const auto result{default_schema_walker("if", VOCABULARIES_DRAFT7)}; - EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueInPlace); + EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorValueOther); EXPECT_TRUE(result.vocabulary.has_value()); EXPECT_EQ(result.vocabulary.value(), "http://json-schema.org/draft-07/schema#");