Class: JSONSkooma::Keywords::Draft201909::UnevaluatedProperties

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/keywords/draft_2019_09/unevaluated_properties.rb

Constant Summary collapse

LOOKUP_KEYWORDS =
%w[properties patternProperties additionalProperties unevaluatedProperties].freeze

Instance Attribute Summary

Attributes inherited from Base

#json, #parent_schema

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/json_skooma/keywords/draft_2019_09/unevaluated_properties.rb', line 18

def evaluate(instance, result)
  evaluated_names = Set.new
  result.parent.collect_annotations(instance, keys: LOOKUP_KEYWORDS) do |node|
    evaluated_names += node.annotation
  end

  annotation = []
  error = []
  instance.each do |name, item|
    next if evaluated_names.include?(name)

    if json.evaluate(item, result).passed?
      annotation << name
    else
      error << name
      # reset to success for the next iteration
      result.success
    end
  end

  return result.failure(error) if error.any?

  result.annotate(annotation)
end