You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
ofobjects
with aminItems
of1
. In order to test a failure case I validate that schema against an array with a single item that isnil
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 containminItems
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?
The text was updated successfully, but these errors were encountered: