Skip to content

Commit

Permalink
Added propertyNames validator to draft6
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Nov 8, 2018
1 parent ab1253a commit 7568595
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Please keep to the changelog format described on [keepachangelog.com](http://kee
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Draft6 validator now supports `propertyNames` validation.

## [2.8.1] - 2018-10-14

Expand Down
23 changes: 23 additions & 0 deletions lib/json-schema/attributes/propertynames.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'json-schema/attribute'

module JSON
class Schema
class PropertyNames < Attribute
def self.validate(current_schema, data, fragments, processor, validator, options = {})
return unless data.is_a?(Hash)

propnames = current_schema.schema['propertyNames']

if propnames.is_a?(Hash)
schema = JSON::Schema.new(propnames, current_schema.uri, validator)
data.each_key do |key|
schema.validate(key, fragments + [key], processor, options)
end
elsif propnames == false && data.any?
message = "The property '#{build_fragment(fragments)}' contains additional properties #{data.keys.inspect} outside of the schema when none are allowed"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/json-schema/validators/draft6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def initialize
"additionalItems" => JSON::Schema::AdditionalItemsAttribute,
"dependencies" => JSON::Schema::DependenciesV4Attribute,
"extends" => JSON::Schema::ExtendsAttribute,
"$ref" => JSON::Schema::RefAttribute
"$ref" => JSON::Schema::RefAttribute,
"propertyNames" => JSON::Schema::PropertyNames
}
@default_formats = {
'date-time' => DateTimeV4Format,
Expand Down
1 change: 0 additions & 1 deletion test/support/test_suite_ignored_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ draft6:
- properties with boolean schema/only 'false' property present is invalid
- properties with boolean schema/no property present is valid
- properties with boolean schema/both properties present is invalid
propertyNames: :all
ref:
- ref overrides any sibling keywords/remote ref valid, maxItems ignored
- ref overrides any sibling keywords/ref valid, maxItems ignored
Expand Down

0 comments on commit 7568595

Please sign in to comment.