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

Added tests for items when data contains more or less types than the schema #127

Merged
merged 1 commit into from
Nov 20, 2016

Conversation

iainbeeston
Copy link
Contributor

What happens if you specify items as an array of types, but you don't include a value for every type? Right now we have no tests for that. We also don't have a test for when there are more values than defined item types.

I've assumed that if the data has fewer values than there are types in the schema, we validate the values that we have. If there are more values than types, we don't validate values that we haven't got schema items for. This might be wrong, but I'd like to open up the discussion (the RFC isn't very clear on how array items should be validated)

Copy link

@jlfaber jlfaber left a comment

Choose a reason for hiding this comment

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

This looks good. I'd suggest adding an empty array test case as well since that should also be valid.

@iainbeeston
Copy link
Contributor Author

Correction: as pointed out to me by @jlfaber this behaviour is defined in the validation RFC:

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".

@Julian
Copy link
Member

Julian commented Sep 30, 2016

Looks great, thanks! Adding one for the empty array does sound like a reasonable idea, and also, if we don't already have it, for the end of that paragraph, i.e. for when there are fewer in the items array but additionalItems is defined.

schema

What happens if you specify items as an array of types, but you don't
include a value for every type? Right now we have no tests for that. We
also don't have a test for when there are more values than defined item
types.
@iainbeeston
Copy link
Contributor Author

I've updated the tests to include an empty array, but I believe the other case is already covered by tests in additionalItems.json

@Julian Julian merged commit efb3c89 into json-schema-org:develop Nov 20, 2016
@Julian
Copy link
Member

Julian commented Nov 20, 2016

Merged, appreciated! Sorry for the delay.

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.

3 participants