-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added propertyNames validator to draft6
- Loading branch information
david
committed
Nov 8, 2018
1 parent
ab1253a
commit 7568595
Showing
4 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters