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

Possible bug: nil items in Array properties are stripped before MinItems validation #129

Closed
dpehrson opened this issue Sep 26, 2014 · 1 comment · Fixed by #140
Closed
Labels

Comments

@dpehrson
Copy link

In lib/json-schema/attributes/minitems.rb on line 5 we have this line:

if data.is_a?(Array) && (data.compact.size < current_schema.schema['minItems'])

The problem is this:

[nil].compact #=> []

In my setup I am testing that a property is an array of objects with a minItems of 1. In order to test a failure case I validate that schema against an array with a single item that is nil and I expect this to fail only because the type of the item is wrong, but it fails both because the type is wrong and because it does not contain minItems

JSON::Validator.fully_validate({type: 'array', minItems: 1, items: {type: 'object'}}, [nil])
=> ["The property '#/' did not contain a minimum number of items 1 in schema 2b6176f7-062b-5706-9ef2-2a6e348b3888#", "The property '#/0' of type NilClass did not match the following type: object in schema 2b6176f7-062b-5706-9ef2-2a6e348b3888#"]

My expectation is that only the second error should be returned, not the first, and based on my reading of the spec, I think that is correct.

Am I wrong or is the code wrong?

@hoxworth
Copy link
Contributor

I believe you are right, and this was more than likely an oversight. This will need to be fixed.

@hoxworth hoxworth added the Bug label Sep 29, 2014
pd added a commit to pd/json-schema that referenced this issue Oct 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants