Skip to content

Commit

Permalink
Simplify router (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkon authored Jul 20, 2023
1 parent 4cf86cb commit a9cbd1b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/openapi_contracts/operation_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ def route(actual_path, 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?(path.path_regexp, actual_path, parameters)
return operation if parameter_match?(m.named_captures, parameters)
end

nil
end

private

def parameter_match?(path_regexp, actual_path, parameters)
path_regexp.match(actual_path) do |m|
m.named_captures.each do |k, v|
return false unless parameters&.find { |s| s.name == k }&.matches?(v)
end
return true
def parameter_match?(actual_params, parameters)
actual_params.each do |k, v|
return false unless parameters&.find { |s| s.name == k }&.matches?(v)
end
false
true
end
end
end

0 comments on commit a9cbd1b

Please sign in to comment.