Method: JSON::Validator#validate_additionalItems
- Defined in:
- lib/json-schema/validator.rb
#validate_additionalItems(current_schema, data, fragments) ⇒ Object
Validate items in an array that are not part of the schema at least match a set of rules
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/json-schema/validator.rb', line 396 def validate_additionalItems(current_schema, data, fragments) if data.is_a?(Array) && current_schema.schema['items'].is_a?(Array) if current_schema.schema['additionalItems'] == false && current_schema.schema['items'].length != data.length = "The property '#{build_fragment(fragments)}' contains additional array elements outside of the schema when none are allowed" raise ValidationError.new(, fragments, current_schema) elsif current_schema.schema['additionalItems'].is_a?(Hash) schema = JSON::Schema.new(current_schema.schema['additionalItems'],current_schema.uri) data.each_with_index do |item,i| if i >= current_schema.schema['items'].length fragments << i.to_s validate_schema(schema, item, fragments) fragments.pop end end end end end |