-
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix unevaluatedItems semantic canonicalisation bugs
#704
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -687,3 +687,107 @@ TEST(AlterSchema_canonicalize_2019_09, items_implicit_1) { | |||||||||||
|
|
||||||||||||
| EXPECT_EQ(document, expected); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| TEST(AlterSchema_canonicalize_2019_09, | ||||||||||||
| items_implicit_skipped_with_unevaluated_items) { | ||||||||||||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "contains": { "type": "boolean" }, | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| CANONICALIZE(document, result, traces); | ||||||||||||
|
|
||||||||||||
| EXPECT_TRUE(result.first); | ||||||||||||
|
|
||||||||||||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "anyOf": [ | ||||||||||||
| { "enum": [ null ] }, | ||||||||||||
| { "enum": [ false, true ] }, | ||||||||||||
| { | ||||||||||||
| "type": "object", | ||||||||||||
| "minProperties": 0, | ||||||||||||
| "properties": {} | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| "type": "array", | ||||||||||||
| "minItems": 0, | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Preserve the explicit Prompt for AI agents
Suggested change
|
||||||||||||
| "contains": { | ||||||||||||
| "enum": [ false, true ] | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| "type": "string", | ||||||||||||
| "minLength": 0 | ||||||||||||
| }, | ||||||||||||
| { "type": "number" } | ||||||||||||
| ], | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| EXPECT_EQ(document, expected); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| TEST(AlterSchema_canonicalize_2019_09, | ||||||||||||
| items_implicit_skipped_with_direct_unevaluated_items) { | ||||||||||||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "type": "array", | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| CANONICALIZE(document, result, traces); | ||||||||||||
|
|
||||||||||||
| EXPECT_TRUE(result.first); | ||||||||||||
|
|
||||||||||||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "type": "array", | ||||||||||||
| "minItems": 0, | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| EXPECT_EQ(document, expected); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| TEST(AlterSchema_canonicalize_2019_09, | ||||||||||||
| items_implicit_skipped_with_anyof_and_unevaluated_items) { | ||||||||||||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "anyOf": [ | ||||||||||||
| { "items": { "type": "boolean" } }, | ||||||||||||
| true | ||||||||||||
| ], | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| CANONICALIZE(document, result, traces); | ||||||||||||
|
|
||||||||||||
| EXPECT_TRUE(result.first); | ||||||||||||
|
|
||||||||||||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||||||||||||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||||||||||||
| "anyOf": [ | ||||||||||||
| { "enum": [ null ] }, | ||||||||||||
| { "enum": [ false, true ] }, | ||||||||||||
| { | ||||||||||||
| "type": "object", | ||||||||||||
| "minProperties": 0, | ||||||||||||
| "properties": {} | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| "type": "array", | ||||||||||||
| "minItems": 0 | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| "type": "string", | ||||||||||||
| "minLength": 0 | ||||||||||||
| }, | ||||||||||||
| { "type": "number" } | ||||||||||||
| ], | ||||||||||||
| "unevaluatedItems": false | ||||||||||||
| })JSON"); | ||||||||||||
|
|
||||||||||||
| EXPECT_EQ(document, expected); | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1697,6 +1697,110 @@ TEST(AlterSchema_canonicalize_2020_12, | |
| EXPECT_EQ(document, expected); | ||
| } | ||
|
|
||
| TEST(AlterSchema_canonicalize_2020_12, | ||
| items_implicit_skipped_with_direct_unevaluated_items) { | ||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "array", | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| CANONICALIZE(document, result, traces); | ||
|
|
||
| EXPECT_TRUE(result.first); | ||
|
|
||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "array", | ||
| "minItems": 0, | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| EXPECT_EQ(document, expected); | ||
| } | ||
|
|
||
| TEST(AlterSchema_canonicalize_2020_12, | ||
| items_implicit_skipped_with_anyof_items_and_unevaluated_items) { | ||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "anyOf": [ | ||
| { "items": { "type": "boolean" } }, | ||
| true | ||
| ], | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| CANONICALIZE(document, result, traces); | ||
|
|
||
| EXPECT_TRUE(result.first); | ||
|
|
||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "anyOf": [ | ||
| { "enum": [ null ] }, | ||
| { "enum": [ false, true ] }, | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Preserve Prompt for AI agents |
||
| "type": "object", | ||
| "minProperties": 0, | ||
| "properties": {} | ||
| }, | ||
| { | ||
| "type": "array", | ||
| "minItems": 0 | ||
| }, | ||
| { | ||
| "type": "string", | ||
| "minLength": 0 | ||
| }, | ||
| { "type": "number" } | ||
| ], | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| EXPECT_EQ(document, expected); | ||
| } | ||
|
|
||
| TEST(AlterSchema_canonicalize_2020_12, | ||
| items_implicit_skipped_with_anyof_prefix_items_and_unevaluated_items) { | ||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "anyOf": [ | ||
| { "prefixItems": [ { "type": "boolean" } ] }, | ||
| true | ||
| ], | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| CANONICALIZE(document, result, traces); | ||
|
|
||
| EXPECT_TRUE(result.first); | ||
|
|
||
| const auto expected = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "anyOf": [ | ||
| { "enum": [ null ] }, | ||
| { "enum": [ false, true ] }, | ||
| { | ||
| "type": "object", | ||
| "minProperties": 0, | ||
| "properties": {} | ||
| }, | ||
| { | ||
| "type": "array", | ||
| "minItems": 0 | ||
| }, | ||
| { | ||
| "type": "string", | ||
| "minLength": 0 | ||
| }, | ||
| { "type": "number" } | ||
| ], | ||
| "unevaluatedItems": false | ||
| })JSON"); | ||
|
|
||
| EXPECT_EQ(document, expected); | ||
| } | ||
|
|
||
| TEST(AlterSchema_canonicalize_2020_12, ref_into_subschema_via_absolute_uri) { | ||
| auto document = sourcemeta::core::parse_json(R"JSON({ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These regressions cover
unevaluatedItemson an ancestor of the array schema; it may also be worth exercising the case where the array schema itself definesunevaluatedItemswith no in-place-applicator parent, sinceWALK_UP_IN_PLACE_APPLICATORSwon’t detect that.Severity: low
Other Locations
test/alterschema/alterschema_canonicalize_2020_12_test.cc:1701🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.