Class: JSONSkooma::Keywords::Applicator::AdditionalProperties
- Defined in:
- lib/json_skooma/keywords/applicator/additional_properties.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#each_schema, inherited, #initialize, #instance_types, #key, #resolve, set_defaults, #static, value_schema=
Constructor Details
This class inherits a constructor from JSONSkooma::Keywords::Base
Instance Method Details
#evaluate(instance, result) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/json_skooma/keywords/applicator/additional_properties.rb', line 12 def evaluate(instance, result) known_property_names = result.sibling(instance, "properties")&.schema_node&.keys || [] known_property_patterns = (result.sibling(instance, "patternProperties")&.schema_node&.keys || []) .map { |pattern| Regexp.new(pattern) } annotation = [] error = [] instance.each do |name, item| if !known_property_names.include?(name) && !known_property_patterns.any? { |pattern| pattern.match?(name) } if json.evaluate(item, result).passed? annotation << name else error << name # reset to success for the next iteration result.success end end end return result.annotate(annotation) if error.empty? result.failure(error) end |