Class: JSONSchemer::Draft201909::Vocab::Core::RecursiveRef

Inherits:
Keyword
  • Object
show all
Defined in:
lib/json_schemer/draft201909/vocab/core.rb

Constant Summary

Constants included from Output

Output::FRAGMENT_ENCODE_REGEX

Instance Attribute Summary

Attributes inherited from Keyword

#parent, #parsed, #root, #value

Attributes included from Output

#keyword, #schema

Instance Method Summary collapse

Methods inherited from Keyword

#absolute_keyword_location, #error_key, #fetch, #initialize, #parsed_schema, #schema_pointer

Methods included from Output

#x_error

Constructor Details

This class inherits a constructor from JSONSchemer::Keyword

Instance Method Details

#recursive_anchorObject



22
23
24
25
# File 'lib/json_schemer/draft201909/vocab/core.rb', line 22

def recursive_anchor
  return @recursive_anchor if defined?(@recursive_anchor)
  @recursive_anchor = (ref_schema.parsed['$recursiveAnchor']&.parsed == true)
end

#ref_schemaObject



18
19
20
# File 'lib/json_schemer/draft201909/vocab/core.rb', line 18

def ref_schema
  @ref_schema ||= root.resolve_ref(ref_uri)
end

#ref_uriObject



14
15
16
# File 'lib/json_schemer/draft201909/vocab/core.rb', line 14

def ref_uri
  @ref_uri ||= URI.join(schema.base_uri, value)
end

#validate(instance, instance_location, keyword_location, context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/json_schemer/draft201909/vocab/core.rb', line 27

def validate(instance, instance_location, keyword_location, context)
  schema = ref_schema

  if recursive_anchor
    context.dynamic_scope.each do |ancestor|
      if ancestor.root.resources.fetch(:dynamic).key?(ancestor.base_uri)
        schema = ancestor.root.resources.fetch(:dynamic).fetch(ancestor.base_uri)
        break
      end
    end
  end

  schema.validate_instance(instance, instance_location, keyword_location, context)
end