Closed jlfaber closed 8 years ago
CI failing due to an issue fixed by #350.
CI now passes. Also updated the common test suite ref. @iainbeeston, this should be ready to go.
:+1:
@jlfaber any chance you can fix up this PR -- I'd love to get this fix in :)
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
@jlfaber I've figured out why the tests are failing on master. Once #360 is merged, and you rebase on top of that, the tests here should pass
@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 https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/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 items
should be used to validate the contents of the array. Here's the best I can find:
if the value of "additionalItems" is boolean value false and the value of "items" is an array, the instance is valid if its size is less than, or equal to, the size of "items".
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 additionalItems
is false
)
Did you mean when additionalItems
is true
? If it's false (meaning additional items are not allowed) and there are more elements in the array than there are in the schema, then that's a clear failure.
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 items
schema:
8.2.3.2. If "items" is an array In this situation, the schema depends on the index: if the index is less than, or equal to, the size of "items", the child instance must be valid against the corresponding schema in the "items" array; otherwise, it must be valid against the schema defined by "additionalItems".
So to summarize: items
can be either a single schema object, which is used to validate all elements of the subject array, or an array of schema objects, each of which is used to validate the corresponding element of the subject array if it exists. The items
attribute itself imposes no restrictions on the length of the subject array.
When items
is not present or is a single schema object, additionalItems
is disregarded.
When items
is an array, additionalItems
may be either true
(the default, which imposes no restrictions at all), false
(which requires that the subject array length be no larger than the length of the items
array), or a single schema object (which is used to validate any subject array elements that do not correspond to a schema in the items
array).
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.