class Openapi3Parser::NodeFactory::Context

This class is used to specify the data and source information for a NodeFactory. The same NodeFactory can be used multiple times if the object is referenced so it is limited in data about it's location within the document.

@attr_reader [Any] input @attr_reader [Source::Location] source_location @attr_reader [Array<Source::Location>] refernce_locations

Constants

UNDEFINED

Attributes

input[R]
reference_locations[R]
source_location[R]

Public Class Methods

new(input, source_location:, reference_locations: []) click to toggle source

@param [Any] input @param [Source::Location] source_location @param [Array<Source::Location>] reference_locations

# File lib/openapi3_parser/node_factory/context.rb, line 69
def initialize(input,
               source_location:,
               reference_locations: [])
  @input = input
  @source_location = source_location
  @reference_locations = reference_locations
end
next_field(parent_context, field, given_input = UNDEFINED) click to toggle source

Create a factory context for a field within the current contexts data eg for a context of:

root = Context.root({ "test" => {} }, source)

we can get the context of “test” with:

test = Context.next_field(root, "test")

@param [Context] parent_context @param [String] field @param [Any] input @return [Context]

# File lib/openapi3_parser/node_factory/context.rb, line 36
def self.next_field(parent_context, field, given_input = UNDEFINED)
  pc = parent_context
  input = if given_input == UNDEFINED
            pc.input.respond_to?(:[]) ? pc.input[field] : nil
          else
            given_input
          end
  source_location = Source::Location.next_field(pc.source_location, field)
  new(input,
      source_location: source_location,
      reference_locations: pc.reference_locations)
end
resolved_reference(reference_context, source_location:) click to toggle source

Creates the context for a field that references another field

@param [Context] reference_context @param [Source::Location] source_location @return [Context]

# File lib/openapi3_parser/node_factory/context.rb, line 54
def self.resolved_reference(reference_context, source_location:)
  reference_locations = [reference_context.source_location] +
                        reference_context.reference_locations

  data = source_location.data if source_location.source_available?
  new(data,
      source_location: source_location,
      reference_locations: reference_locations)
end
root(input, source) click to toggle source

Create a context for the root of a document

@param [Any] input @param [Source] source @return [Context]

# File lib/openapi3_parser/node_factory/context.rb, line 22
def self.root(input, source)
  new(input, source_location: Source::Location.new(source, []))
end

Public Instance Methods

==(other) click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node_factory/context.rb, line 78
def ==(other)
  input == other.input &&
    source_location == other.source_location &&
    reference_locations == other.reference_locations
end
inspect() click to toggle source
# File lib/openapi3_parser/node_factory/context.rb, line 104
def inspect
  %{#{self.class.name}(source_location: #{source_location}, } +
    %{referenced_by: #{reference_locations.map(&:to_s).join(', ')})}
end
location_summary() click to toggle source
# File lib/openapi3_parser/node_factory/context.rb, line 109
def location_summary
  source_location.to_s
end
resolve_reference(reference, factory, recursive: false) click to toggle source

@param [String] reference @param [Object, Map, Array] factory @param [Boolean] recursive @return [Source::ResolvedReference]

# File lib/openapi3_parser/node_factory/context.rb, line 93
def resolve_reference(reference, factory, recursive: false)
  source.resolve_reference(reference, factory, self, recursive: recursive)
end
self_referencing?() click to toggle source

Used to show when an recursive reference loop has begun

@return [Boolean]

# File lib/openapi3_parser/node_factory/context.rb, line 100
def self_referencing?
  reference_locations.include?(source_location)
end
source() click to toggle source

@return [Source]

# File lib/openapi3_parser/node_factory/context.rb, line 85
def source
  source_location.source
end
to_s() click to toggle source
# File lib/openapi3_parser/node_factory/context.rb, line 113
def to_s
  location_summary
end