Class: Openapi3Parser::Node::Object

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/openapi3_parser/node/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, context) ⇒ Object

Returns a new instance of Object.



16
17
18
19
# File 'lib/openapi3_parser/node/object.rb', line 16

def initialize(data, context)
  @node_data = data
  @node_context = context
end

Instance Attribute Details

#node_contextObject (readonly)

Returns the value of attribute node_context.



14
15
16
# File 'lib/openapi3_parser/node/object.rb', line 14

def node_context
  @node_context
end

#node_dataObject (readonly)

Returns the value of attribute node_data.



14
15
16
# File 'lib/openapi3_parser/node/object.rb', line 14

def node_data
  @node_data
end

Instance Method Details

#[](value) ⇒ Object

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

Examples:

Look up by OpenAPI naming

obj["externalDocs"]

Look up by symbol

obj[:servers]

Look up an extension

obj["x-myExtension"]

Parameters:

  • value (String, Symbol)

Returns:

  • anything



36
37
38
# File 'lib/openapi3_parser/node/object.rb', line 36

def [](value)
  node_data[value.to_s]
end

#extension(value) ⇒ Hash, ...

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

Examples:

Looking up an extension provided as “x-extra”

obj.extension("extra")

Parameters:

  • value (String, Symbol)

Returns:

  • (Hash, Array, Numeric, String, true, false, nil)


49
50
51
# File 'lib/openapi3_parser/node/object.rb', line 49

def extension(value)
  node_data["x-#{value}"]
end

#inspectString

Returns:

  • (String)


77
78
79
80
# File 'lib/openapi3_parser/node/object.rb', line 77

def inspect
  fragment = node_context.document_location.pointer.fragment
  %{#{self.class.name}(#{fragment})}
end

#node_at(pointer_like) ⇒ Object

Used to access a node relative to this node

Examples:

Looking up the parent node of this node

obj.node_at("#..")

Jumping way down the tree

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

Parameters:

Returns:

  • anything



71
72
73
74
# File 'lib/openapi3_parser/node/object.rb', line 71

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) ⇒ String?

Used to render fields that can be in markdown syntax into HTML

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


56
57
58
59
# File 'lib/openapi3_parser/node/object.rb', line 56

def render_markdown(value)
  return if value.nil?
  Markdown.to_html(value)
end