-
-
Notifications
You must be signed in to change notification settings - Fork 5
Linter: create rule to remove additional items when items is an object #1805
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
base: main
Are you sure you want to change the base?
Linter: create rule to remove additional items when items is an object #1805
Conversation
…en items is an objects Signed-off-by: karan-palan <karanpalan007@gmail.com>
@@ -52,6 +52,7 @@ static auto every_item_is_boolean(const T &container) -> bool { | |||
#include "linter/content_media_type_without_encoding.h" | |||
#include "linter/content_schema_default.h" | |||
#include "linter/content_schema_without_media_type.h" | |||
#include "linter/dangling_additional_items.h" |
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.
Can we all it additional_items_with_schema_items
? The dangling
part seems confusing at first and other rules follow the with
and without
convention. I think additional_items_with_schema_items
is still short enough and very self-explanatory
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.
Also, you have to update the CMakeLists.txt
file to list this file too
{"https://json-schema.org/draft/2019-09/vocab/applicator", | ||
"http://json-schema.org/draft-07/schema#", | ||
"http://json-schema.org/draft-06/schema#", | ||
"http://json-schema.org/draft-04/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.
I believe this rule applies to Draft 3 as well. Can you confirm on the spec?
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.
Yes it does, adding tests for it as well
@@ -1661,8 +1661,7 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_ref_wrapper_5) { | |||
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ | |||
"$schema": "https://json-schema.org/draft/2019-09/schema", | |||
"allOf": [ | |||
{ | |||
"type": "integer", | |||
{ "type": "integer", |
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.
Unintended change?
I left a few comments. On testing:
|
@jviotti , the PR is ready for review |
"http://json-schema.org/draft-04/schema#", | ||
"http://json-schema.org/draft-03/schema#"}) && | ||
schema.is_object() && schema.defines("items") && | ||
schema.defines("additionalItems") && schema.at("items").is_object(); |
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.
The is_object
check for items
is still wrong, as the items
keyword can be set to a boolean. Remember that in JSON Schema, a schema is either an object or a boolean. We have an is_schema
function for this case
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.
Also I think you are missing test cases covering that case: items
set to a boolean
"http://json-schema.org/draft-04/schema#", | ||
"http://json-schema.org/draft-03/schema#"}) && | ||
schema.is_object() && schema.defines("items") && | ||
schema.defines("additionalItems") && schema.at("items").is_object(); |
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.
schema.defines("additionalItems") && schema.at("items").is_object(); | |
schema.defines("additionalItems") && is_schema(schema.at("items")); |
…undo unintended change Signed-off-by: karan-palan <karanpalan007@gmail.com>
7c994f5
to
bb30244
Compare
Signed-off-by: karan-palan <karanpalan007@gmail.com>
I guess I understood, this is how the rule works now:
|
That explanation makes sense! |
…ng-additional-items
Signed-off-by: karan-palan <karanpalan007@gmail.com>
…ng-additional-items
@jviotti , resolved merge conflicts. Any comments? |
Implementation
Rule ID: dangling_additional_items
Description: "
additionalItems
is ignored whenitems
is an object"Condition: Detects
additionalItems
in JSON Schema objects whereitems
is an object (not an array).Transform: Removes the redundant
additionalItems
property.Dialects: Supports draft4, draft6, draft7, and 2019-09. Excluded for draft-2020-12 (where
additionalItems
was removed from the spec).Test Cases
Positive Cases: Removal of
additionalItems
whenitems
is an object.Negative Cases: No change for
items
as an array or whenitems
is undefined.Edge Cases: Complex
items
objects (e.g., withif
/then
conditions) - correctly handled.Context Preservation: Tests with various other keywords to ensure proper behavior.