-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Item partial tuples #348
Item partial tuples #348
Conversation
CI failing due to an issue fixed by #350. |
91f328e
to
acd777d
Compare
CI now passes. Also updated the common test suite ref. |
@@ -16,6 +16,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options | |||
|
|||
when Array | |||
items.each_with_index do |item_schema, i| | |||
next unless i < data.length |
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.
Couldn't this be replaced by break if i >= data.length
?
👍 |
@jlfaber any chance you can fix up this PR -- I'd love to get this fix in :) |
ab384f4
to
0cd6ec0
Compare
I've rebased, but this is now failing (again) due to another unrelated issue. #357 |
It looks like something changed in the common test suite, that's also causing master to fail. I'll take a closer look at that issue |
#360 is merged |
When 'items' is an array of schemas, allow 'items' and 'additionalItems' validations to pass even when the target array has fewer elements than items.
0cd6ec0
to
d9b0e59
Compare
@iainbeeston tests now passing -- ready to merge. Thx for the fix in #360 ! |
Great - I'll take one last look at this today and hopefully get it merged and released |
Thanks @jlfaber I've merged that, and I'll try to get it released soon. Interestingly the original json-schema spec is very vague about how this should work. I'm going to add some extra tests to the common test suite so we can be sure we are doing the right thing |
My PR on the common test suite is json-schema-org/JSON-Schema-Test-Suite#127 |
Thanks @iainbeeston for the merge. The current schema validation spec (http://json-schema.org/latest/json-schema-validation.html#anchor37) is pretty specific about how items should work. Note the example 5.3.1.3 which shows this schema: {
"items": [ {}, {}, {} ],
"additionalItems": false
} and these examples of valid instances: []
[ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ]
[ 1, 2, 3 ] The valid arrays have zero, two, and three elements, respectively. |
Yes that's true, but what I was thinking of was that it doesn't explain how the schemas in
It seems safe to assume that each consecutive array element should match the schema in items at the same position, but then what happens when there are more elements in the array than there are items in the schema? (only relevant if |
Did you mean when This section (http://json-schema.org/latest/json-schema-validation.html#anchor131) offers a bit more guidance about validating the elements of an array against an
So to summarize: When When |
Currently, when 'items' is an array of schemas, validation will fail if the target array has fewer elements than the 'items' array. This conflicts with the spec, which allows for partial (or even empty) tuples to pass validation unless 'minItems' is also set.
See the relevant section of Understanding JSON Schema for examples of this. Note specifically the statement: "It's okay to not provide all the items."
This PR modifies the array_validation tests to check for this condition and fixes the corresponding code in the attributes directory.