Class: Openapi3Parser::NodeFactory::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/node_factory/reference.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#context, #data

Instance Method Summary collapse

Methods inherited from Object

#allowed_fields, #can_use_default?, #default, #inspect, #nil_input?, #node, object_type, #raw_input, #required_fields, #resolved_input, #valid?

Methods included from ObjectFactory::Dsl

#allow_extensions, #allowed_extensions?, #field, #field_configs, #mutually_exclusive, #mutually_exclusive_fields, #validate, #validations

Constructor Details

#initialize(context, factory) ⇒ Reference

Returns a new instance of Reference.



12
13
14
15
# File 'lib/openapi3_parser/node_factory/reference.rb', line 12

def initialize(context, factory)
  @factory = factory
  super(context)
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



10
11
12
# File 'lib/openapi3_parser/node_factory/reference.rb', line 10

def factory
  @factory
end

Instance Method Details

#errorsObject



35
36
37
38
39
40
41
# File 'lib/openapi3_parser/node_factory/reference.rb', line 35

def errors
  if in_recursive_loop?
    @errors ||= Validation::ErrorCollection.new
  else
    super
  end
end

#in_recursive_loop?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/openapi3_parser/node_factory/reference.rb', line 17

def in_recursive_loop?
  data["$ref"].self_referencing?
end

#referenced_factoryObject



21
22
23
# File 'lib/openapi3_parser/node_factory/reference.rb', line 21

def referenced_factory
  data["$ref"].referenced_factory
end

#resolves?(control_factory = nil) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/openapi3_parser/node_factory/reference.rb', line 25

def resolves?(control_factory = nil)
  control_factory ||= self

  return true unless referenced_factory.is_a?(Reference)
  # recursive loop of references that never references an object
  return false if referenced_factory == control_factory

  referenced_factory.resolves?(control_factory)
end