Skip to content

Commit 9bd132f

Browse files
committed
Introduce resolve_path()
1 parent 212668a commit 9bd132f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/openapi_first.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ def self.configure
3535
ERROR_RESPONSES = {} # rubocop:disable Style/MutableConstant
3636
private_constant :ERROR_RESPONSES
3737

38-
# Retrieve the path used for schema matching.
39-
#
40-
# @param [Rack::Request] rack_request
41-
def self.get_path_to_match(rack_request)
42-
rack_request.env[PATH] || rack_request.path
43-
end
44-
4538
# Register an error response class
4639
# @param name [Symbol]
4740
# @param klass [Class] A class that includes / implements OpenapiFirst::ErrorResponse

lib/openapi_first/definition.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def initialize(contents, filepath = nil)
4545
# @param [Boolean] raise_error Whether to raise an error if validation fails.
4646
# @return [ValidatedRequest] The validated request object.
4747
def validate_request(request, raise_error: false)
48-
route = @router.match(request.request_method, OpenapiFirst.get_path_to_match(request), content_type: request.content_type)
48+
route = @router.match(request.request_method, resolve_path(request), content_type: request.content_type)
4949
if route.error
5050
ValidatedRequest.new(request, error: route.error)
5151
else
@@ -62,7 +62,7 @@ def validate_request(request, raise_error: false)
6262
# @param raise_error [Boolean] Whethir to raise an error if validation fails.
6363
# @return [ValidatedResponse] The validated response object.
6464
def validate_response(rack_request, rack_response, raise_error: false)
65-
route = @router.match(rack_request.request_method, OpenapiFirst.get_path_to_match(rack_request), content_type: rack_request.content_type)
65+
route = @router.match(rack_request.request_method, resolve_path(rack_request), content_type: rack_request.content_type)
6666
return if route.error # Skip response validation for unknown requests
6767

6868
response_match = route.match_response(status: rack_response.status, content_type: rack_response.content_type)
@@ -76,5 +76,11 @@ def validate_response(rack_request, rack_response, raise_error: false)
7676
raise validated.error.exception(validated) if raise_error && validated.invalid?
7777
end
7878
end
79+
80+
private
81+
82+
def resolve_path(rack_request)
83+
rack_request.env[PATH] || rack_request.path
84+
end
7985
end
8086
end

0 commit comments

Comments
 (0)