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

support for additionalItems #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hudson-ai
Copy link
Collaborator

closes #86

@hudson-ai hudson-ai requested a review from mmoskal December 11, 2024 00:30
Comment on lines 614 to 621
match (get("items"), get("additionalItems")) {
(Some(items), None) => Some(items),
(None, Some(additional_items)) => Some(additional_items),
(Some(_), Some(_)) => {
bail!("Cannot specify both 'items' and 'additionalItems'")
}
_ => None,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could alternatively only look for the one that's valid under the detected draft? That being said, I don't think a lot of folks actually annotate their schema with the draft, so that may be kind of useless... thoughts @mmoskal ?

@mmoskal
Copy link
Collaborator

mmoskal commented Dec 11, 2024

There is ~200 cases with additionalItems being true (16 cases) or false (188 cases) and items being present.

(llg) [12:31 unique_tests]$ rg @itemsAndAdditionalItemsFalse -l |head
Github_hard---o21439.json
Github_hard---o21252.json
Github_hard---o21244.json
Github_medium---o81496.json
Github_hard---o21268.json
Github_hard---o21356.json
Github_easy---o46155.json
Github_easy---o10059.json
Github_hard---o21292.json
Github_hard---o21157.json
(llg) [12:31 unique_tests]$ rg @itemsAndAdditionalItemsTrue -l |head
Github_medium---o24180.json
Github_hard---o14404.json
Github_trivial---o2141.json
Github_medium---o6290.json
Github_medium---o24174.json
Github_medium---o76785.json
Github_medium---o24172.json
Github_hard---o64539.json
Github_easy---o58271.json
Github_medium---o68444.json

There is in fact only 4 cases with additionalItems being an object:

(llg) [12:33 unique_tests]$ rg additionalItems:object -l
Github_medium---o69991.json
Github_medium---o16744.json
Github_medium---o60170.json
Github_medium---o83807.json
(llg) [12:33 unique_tests]$ 

@hudson-ai
Copy link
Collaborator Author

hudson-ai commented Dec 11, 2024

@mmoskal I was mistaken about the semantics of additionalItems

https://json-schema.org/understanding-json-schema/reference/array

In Draft 4 - 2019-09, tuple validation was handled by an alternate form of the items keyword. When items was an array of schemas instead of a single schema, it behaved the way prefixItems behaves.

Before to Draft 2020-12, you would use the additionalItems keyword to constrain additional items on a tuple. It works the same as items, only the name has changed.

In Draft 6 - 2019-09, the additionalItems keyword is ignored if there is not a "tuple validation" items keyword present in the same schema.

I'm still a bit confused about the semantics between draft 4 and 6...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement additionalItems
2 participants