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

Item partial tuples #348

Merged
merged 3 commits into from
Sep 29, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix validation of partial tuples
When 'items' is an array of schemas, allow 'items' and 'additionalItems'
validations to pass even when the target array has fewer elements than items.
Joe Faber committed Sep 28, 2016
commit 06709b0be790cb28522c021dac8b33bc304e8869
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Made sure we really do clear the cache when instructed to
- It's now possible to use reserved words in property names
- Removed support for setting "extends" to a string (it's invalid json-schema - use a "$ref" instead)
- Relaxed 'items' and 'allowedItems' validation to permit arrays to pass even
when they contain fewer elements than the 'items' array. To require full tuples,
use 'minItems'.

### Changed
- Made all `validate*` methods on `JSON::Validator` ultimately call `validate!`
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/additionalitems.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options

case schema['additionalItems']
when false
if schema['items'].length != data.length
if schema['items'].length < data.length
message = "The property '#{build_fragment(fragments)}' contains additional array elements outside of the schema when none are allowed"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
end
1 change: 1 addition & 0 deletions lib/json-schema/attributes/items.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options

when Array
items.each_with_index do |item_schema, i|
next unless i < data.length
Copy link
Contributor

@RST-J RST-J Jul 27, 2016

Choose a reason for hiding this comment

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

Couldn't this be replaced by break if i >= data.length?

schema = JSON::Schema.new(item_schema, current_schema.uri, validator)
schema.validate(data[i], fragments + [i.to_s], processor, options)
end