Class: JSONSchemer::Draft202012::Vocab::Applicator::PatternProperties
- Inherits:
-
Keyword
- Object
- Keyword
- JSONSchemer::Draft202012::Vocab::Applicator::PatternProperties
- Defined in:
- lib/json_schemer/draft202012/vocab/applicator.rb
Constant Summary
Constants included from Output
Instance Attribute Summary
Attributes inherited from Keyword
#parent, #parsed, #root, #value
Attributes included from Output
Instance Method Summary collapse
- #error(formatted_instance_location:) ⇒ Object
- #parse ⇒ Object
- #validate(instance, instance_location, keyword_location, context) ⇒ Object
Methods inherited from Keyword
#absolute_keyword_location, #error_key, #fetch, #initialize, #parsed_schema, #schema_pointer
Methods included from Output
Constructor Details
This class inherits a constructor from JSONSchemer::Keyword
Instance Method Details
#error(formatted_instance_location:) ⇒ Object
267 268 269 |
# File 'lib/json_schemer/draft202012/vocab/applicator.rb', line 267 def error(formatted_instance_location:, **) "object properties at #{formatted_instance_location} do not match corresponding `patternProperties` schemas" end |
#parse ⇒ Object
271 272 273 274 275 |
# File 'lib/json_schemer/draft202012/vocab/applicator.rb', line 271 def parse value.each_with_object({}) do |(pattern, subschema), out| out[pattern] = subschema(subschema, pattern) end end |
#validate(instance, instance_location, keyword_location, context) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/json_schemer/draft202012/vocab/applicator.rb', line 277 def validate(instance, instance_location, keyword_location, context) return result(instance, instance_location, keyword_location, true) unless instance.is_a?(Hash) evaluated = Set[] nested = [] parsed.each do |pattern, subschema| regexp = root.resolve_regexp(pattern) instance.each do |key, value| if regexp.match?(key) evaluated << key nested << subschema.validate_instance(value, join_location(instance_location, key), join_location(keyword_location, pattern), context) end end end result(instance, instance_location, keyword_location, nested.all?(&:valid), nested, :annotation => evaluated.to_a) end |