Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark allOf as an inline-able applicator #1406

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/jsonschema/default_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
ApplicatorElementsInPlace)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "anyOf",
ApplicatorElementsInPlace)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "allOf",
ApplicatorElementsInPlace)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "allOf", ApplicatorElementsInline)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "if", ApplicatorValueOther)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "then", ApplicatorValueInPlace,
"if")
Expand Down Expand Up @@ -118,8 +117,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
WALK(HTTPS_BASE "2019-09/vocab/core", "$vocabulary", Other)
WALK(HTTPS_BASE "2019-09/vocab/core", "$recursiveRef", Reference)
WALK(HTTPS_BASE "2019-09/vocab/core", "$recursiveAnchor", Other)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "allOf",
ApplicatorElementsInPlace)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "allOf", ApplicatorElementsInline)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "anyOf",
ApplicatorElementsInPlace)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "oneOf",
Expand Down Expand Up @@ -237,7 +235,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
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#", "allOf", ApplicatorElementsInline, "$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", ApplicatorValueOther, "$ref")
Expand Down Expand Up @@ -305,7 +303,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
WALK(HTTP_BASE "draft-06/schema#", "dependencies", ApplicatorMembers, "$ref")
WALK(HTTP_BASE "draft-06/schema#", "propertyNames", ApplicatorValueInPlace,
"$ref")
WALK(HTTP_BASE "draft-06/schema#", "allOf", ApplicatorElementsInPlace, "$ref")
WALK(HTTP_BASE "draft-06/schema#", "allOf", ApplicatorElementsInline, "$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", ApplicatorValueOther, "$ref")
Expand Down Expand Up @@ -366,7 +364,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
WALK(HTTP_BASE "draft-04/schema#", "additionalProperties", ApplicatorValue,
"properties", "patternProperties")
WALK(HTTP_BASE "draft-04/schema#", "dependencies", ApplicatorMembers, "$ref")
WALK(HTTP_BASE "draft-04/schema#", "allOf", ApplicatorElementsInPlace, "$ref")
WALK(HTTP_BASE "draft-04/schema#", "allOf", ApplicatorElementsInline, "$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", ApplicatorValueOther, "$ref")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ enum class SchemaWalkerStrategy : std::uint8_t {
/// as an argument without affecting the instance location
ApplicatorElementsInPlace,
/// The JSON Schema keyword is an applicator that potentially
/// takes an array of potentially JSON Schema definitions
/// as an argument without affecting the instance location and that can be
/// statically inlined
ApplicatorElementsInline,
/// The JSON Schema keyword is an applicator that potentially
/// takes an object as argument, whose values are potentially
/// JSON Schema definitions
ApplicatorMembers,
Expand Down
3 changes: 3 additions & 0 deletions src/jsonschema/walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ auto walk(sourcemeta::jsontoolkit::Pointer &pointer,
} break;
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::ApplicatorElements:
[[fallthrough]];
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::
ApplicatorElementsInline:
[[fallthrough]];
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::
ApplicatorElementsInPlace:
if (pair.second.is_array()) {
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_2019_09_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ TEST(JSONSchema_default_walker_2019_09, applicator_allOf) {
using namespace sourcemeta::jsontoolkit;
const auto result{
default_schema_walker("allOf", VOCABULARIES_2019_09_APPLICATOR)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInPlace);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInline);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"https://json-schema.org/draft/2019-09/vocab/applicator");
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_2020_12_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST(JSONSchema_default_walker_2020_12, applicator_allOf) {
using namespace sourcemeta::jsontoolkit;
const auto result{
default_schema_walker("allOf", VOCABULARIES_2020_12_APPLICATOR)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInPlace);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInline);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"https://json-schema.org/draft/2020-12/vocab/applicator");
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_draft4_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST(JSONSchema_default_walker_draft4, definitions) {
TEST(JSONSchema_default_walker_draft4, allOf) {
using namespace sourcemeta::jsontoolkit;
const auto result{default_schema_walker("allOf", VOCABULARIES_DRAFT4)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInPlace);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInline);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"http://json-schema.org/draft-04/schema#");
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_draft6_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST(JSONSchema_default_walker_draft6, definitions) {
TEST(JSONSchema_default_walker_draft6, allOf) {
using namespace sourcemeta::jsontoolkit;
const auto result{default_schema_walker("allOf", VOCABULARIES_DRAFT6)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInPlace);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInline);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"http://json-schema.org/draft-06/schema#");
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_draft7_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TEST(JSONSchema_default_walker_draft7, comment) {
TEST(JSONSchema_default_walker_draft7, allOf) {
using namespace sourcemeta::jsontoolkit;
const auto result{default_schema_walker("allOf", VOCABULARIES_DRAFT7)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInPlace);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorElementsInline);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"http://json-schema.org/draft-07/schema#");
Expand Down
Loading