Method: OpenapiContracts::OperationRouter#route

Defined in:
lib/openapi_contracts/operation_router.rb

#route(actual_path, method) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openapi_contracts/operation_router.rb', line 8

def route(actual_path, method)
  @doc.with_path(actual_path)&.then { |p| return p.with_method(method) }

  @dynamic_paths.each do |path|
    next unless path.supports_method?(method)
    next unless m = path.path_regexp.match(actual_path)

    operation = path.with_method(method)
    parameters = (path.parameters + operation.parameters).select(&:in_path?)

    return operation if parameter_match?(m.named_captures, parameters)
  end

  nil
end