Class: OpenAPIParser::PathItemFinder

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

Defined Under Namespace

Classes: PathNode, Result

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ PathItemFinder

Returns a new instance of PathItemFinder.

Parameters:



3
4
5
6
7
8
# File 'lib/openapi_parser/path_item_finder.rb', line 3

def initialize(paths)
  @root = PathNode.new('/')
  @paths = paths

  @paths.path.each { |path, _path_item_object| @root.register_path_node(path.split('/'), path) }
end

Instance Method Details

#operation_object(http_method, request_path) ⇒ Result?

find operation object and if not exist return nil

Parameters:

  • http_method (String, Symbol)

    like (get, post .… allow symbol)

  • request_path (String)

Returns:



14
15
16
17
18
19
20
21
22
23
# File 'lib/openapi_parser/path_item_finder.rb', line 14

def operation_object(http_method, request_path)
  if (path_item_object = @paths.path[request_path])
    if (op = path_item_object.operation(http_method))
      return Result.new(path_item_object, op, request_path, {}) # find no path_params path
    end
  end

  # check with path_params
  parse_request_path(http_method, request_path)
end