class Openapi3Parser::Node::Object

Attributes

node_context[R]
node_data[R]

Public Class Methods

new(data, context) click to toggle source
# File lib/openapi3_parser/node/object.rb, line 14
def initialize(data, context)
  @node_data = data
  @node_context = context
end

Public Instance Methods

==(other) click to toggle source

@param [Any] other

@return [Boolean]

# File lib/openapi3_parser/node/object.rb, line 54
def ==(other)
  other.instance_of?(self.class) &&
    node_context.same_data_and_source?(other.node_context)
end
[](value) click to toggle source

Look up an attribute of the node by the name it has in the OpenAPI document.

@example Look up by OpenAPI naming

obj["externalDocs"]

@example Look up by symbol

obj[:servers]

@example Look up an extension

obj["x-myExtension"]

@param [String, Symbol] value

@return anything

# File lib/openapi3_parser/node/object.rb, line 34
def [](value)
  Placeholder.resolve(node_data[value.to_s])
end
each(&block) click to toggle source

Iterates through the data of this node, used by Enumerable

@return [Object]

# File lib/openapi3_parser/node/object.rb, line 62
def each(&block)
  Placeholder.each(node_data, &block)
end
extension(value) click to toggle source

Look up an extension provided for this object, doesn't need a prefix of “x-”

@example Looking up an extension provided as “x-extra”

obj.extension("extra")

@param [String, Symbol] value

@return [Hash, Array, Numeric, String, true, false, nil]

# File lib/openapi3_parser/node/object.rb, line 47
def extension(value)
  self["x-#{value}"]
end
inspect() click to toggle source

@return [String]

# File lib/openapi3_parser/node/object.rb, line 99
def inspect
  fragment = node_context.document_location.pointer.fragment
  %{#{self.class.name}(#{fragment})}
end
node_at(pointer_like) click to toggle source

Used to access a node relative to this node

@example Looking up the parent node of this node

obj.node_at("#..")

@example Jumping way down the tree

obj.node_at("#properties/Field/type")

@param [Source::Pointer, ::Array, ::String] pointer_like @return anything

# File lib/openapi3_parser/node/object.rb, line 93
def node_at(pointer_like)
  current_pointer = node_context.document_location.pointer
  node_context.document.node_at(pointer_like, current_pointer)
end
render_markdown(value) click to toggle source

Used to render fields that can be in markdown syntax into HTML @param [String, nil] value @return [String, nil]

# File lib/openapi3_parser/node/object.rb, line 77
def render_markdown(value)
  return if value.nil?

  Markdown.to_html(value)
end
values() click to toggle source

Provide an array of values for this object, a partner to the keys method

@return [Array]

# File lib/openapi3_parser/node/object.rb, line 70
def values
  map(&:last)
end