Class: Openapi3Parser::NodeFactory::Fields::Reference

Inherits:
Openapi3Parser::NodeFactory::Field show all
Defined in:
lib/openapi3_parser/node_factory/fields/reference.rb

Defined Under Namespace

Classes: RecursiveResolvedInput

Instance Attribute Summary

Attributes inherited from Openapi3Parser::NodeFactory::Field

#context, #input_type, #validation

Instance Method Summary collapse

Methods inherited from Openapi3Parser::NodeFactory::Field

#data, #default, #errors, #inspect, #nil_input?, #node, #raw_input, #valid?

Constructor Details

#initialize(context, factory) ⇒ Reference

Returns a new instance of Reference.



13
14
15
16
17
18
19
# File 'lib/openapi3_parser/node_factory/fields/reference.rb', line 13

def initialize(context, factory)
  context = Context.as_reference(context)
  super(context, input_type: String, validate: :validate)
  @factory = factory
  @reference = context.input
  @reference_resolver = create_reference_resolver
end

Instance Method Details

#in_recursive_loop?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/openapi3_parser/node_factory/fields/reference.rb', line 31

def in_recursive_loop?
  context.source_location == reference_context&.source_location
end

#reference_contextObject



35
36
37
# File 'lib/openapi3_parser/node_factory/fields/reference.rb', line 35

def reference_context
  context.referenced_by
end

#resolved_inputObject



21
22
23
24
25
26
27
28
29
# File 'lib/openapi3_parser/node_factory/fields/reference.rb', line 21

def resolved_input
  return unless reference_resolver

  if in_recursive_loop?
    RecursiveResolvedInput.new(reference_context)
  else
    reference_resolver.resolved_input
  end
end