Class: OpenAPIParser::PathItemFinder::PathNode

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_parser/path_item_finder.rb

Overview

path tree node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PathNode

Returns a new instance of PathNode.



48
49
50
51
52
53
# File 'lib/openapi_parser/path_item_finder.rb', line 48

def initialize(name)
  @name = name
  @children = Hash.new { |h, k| h[k] = PathNode.new(k) }
  @path_template_node = nil # we can't initialize because recursive initialize...
  @full_path = nil
end

Instance Attribute Details

#full_pathObject

Returns the value of attribute full_path.



46
47
48
# File 'lib/openapi_parser/path_item_finder.rb', line 46

def full_path
  @full_path
end

#nameObject

Returns the value of attribute name.



46
47
48
# File 'lib/openapi_parser/path_item_finder.rb', line 46

def name
  @name
end

Instance Method Details

#find_full_path(splited_path) ⇒ String?

Returns and Hash.

Returns:

  • (String, nil)

    and Hash



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/openapi_parser/path_item_finder.rb', line 70

def find_full_path(splited_path)
  return [@full_path, {}] if splited_path.empty?

  path_name = splited_path.shift

  # when ambiguous matching like this
  # /{entity}/me
  # /books/{id}
  # OpenAPI3 depend on the tooling so we use concrete one (using /books/)

  path_params = {}
  if children.has_key?(path_name)
    child = children[path_name]
  else
    child = path_template_node(path_name)
    path_params = { child.name.to_s => path_name }
  end

  ret, other_path_params = child.find_full_path(splited_path)
  [ret, path_params.merge(other_path_params)]
end

#register_path_node(splited_path, full_path) ⇒ Object

Parameters:

  • splited_path (Array<string>)
  • full_path (String)


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/openapi_parser/path_item_finder.rb', line 57

def register_path_node(splited_path, full_path)
  if splited_path.empty?
    @full_path = full_path
    return
  end

  path_name = splited_path.shift

  child = path_template?(path_name) ? path_template_node(path_name) : children[path_name]
  child.register_path_node(splited_path, full_path)
end