Skip to content

Commit 5c9353d

Browse files
committed
path finder find sig refactor
1 parent 18f6b0f commit 5c9353d

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

openapi_core/templating/paths/finders.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,27 @@ def __init__(self, spec, base_url=None):
1919
self.spec = spec
2020
self.base_url = base_url
2121

22-
def find(self, request):
23-
paths_iter = self._get_paths_iter(request.full_url_pattern)
22+
def find(self, method, full_url_pattern):
23+
paths_iter = self._get_paths_iter(full_url_pattern)
2424
paths_iter_peek = peekable(paths_iter)
2525

2626
if not paths_iter_peek:
27-
raise PathNotFound(request.full_url_pattern)
27+
raise PathNotFound(full_url_pattern)
2828

29-
operations_iter = self._get_operations_iter(
30-
request.method, paths_iter_peek
31-
)
29+
operations_iter = self._get_operations_iter(method, paths_iter_peek)
3230
operations_iter_peek = peekable(operations_iter)
3331

3432
if not operations_iter_peek:
35-
raise OperationNotFound(request.full_url_pattern, request.method)
33+
raise OperationNotFound(full_url_pattern, method)
3634

3735
servers_iter = self._get_servers_iter(
38-
request.full_url_pattern, operations_iter_peek
36+
full_url_pattern, operations_iter_peek
3937
)
4038

4139
try:
4240
return next(servers_iter)
4341
except StopIteration:
44-
raise ServerNotFound(request.full_url_pattern)
42+
raise ServerNotFound(full_url_pattern)
4543

4644
def _get_paths_iter(self, full_url_pattern):
4745
template_paths = []

openapi_core/validation/request/validators.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def _get_body_value(self, request_body, request):
176176
class RequestParametersValidator(BaseRequestValidator):
177177
def validate(self, request):
178178
try:
179-
path, operation, _, path_result, _ = self._find_path(request)
179+
path, operation, _, path_result, _ = self._find_path(
180+
request.method, request.full_url_pattern
181+
)
180182
except PathError as exc:
181183
return RequestValidationResult(errors=[exc])
182184

@@ -195,7 +197,9 @@ def validate(self, request):
195197
class RequestBodyValidator(BaseRequestValidator):
196198
def validate(self, request):
197199
try:
198-
_, operation, _, _, _ = self._find_path(request)
200+
_, operation, _, _, _ = self._find_path(
201+
request.method, request.full_url_pattern
202+
)
199203
except PathError as exc:
200204
return RequestValidationResult(errors=[exc])
201205

@@ -210,7 +214,9 @@ def validate(self, request):
210214
class RequestSecurityValidator(BaseRequestValidator):
211215
def validate(self, request):
212216
try:
213-
_, operation, _, _, _ = self._find_path(request)
217+
_, operation, _, _, _ = self._find_path(
218+
request.method, request.full_url_pattern
219+
)
214220
except PathError as exc:
215221
return RequestValidationResult(errors=[exc])
216222

@@ -228,7 +234,9 @@ def validate(self, request):
228234
class RequestValidator(BaseRequestValidator):
229235
def validate(self, request):
230236
try:
231-
path, operation, _, path_result, _ = self._find_path(request)
237+
path, operation, _, path_result, _ = self._find_path(
238+
request.method, request.full_url_pattern
239+
)
232240
# don't process if operation errors
233241
except PathError as exc:
234242
return RequestValidationResult(errors=[exc])

openapi_core/validation/response/validators.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def schema_unmarshallers_factory(self):
3333
)
3434

3535
def _find_operation_response(self, request, response):
36-
_, operation, _, _, _ = self._find_path(request)
36+
_, operation, _, _, _ = self._find_path(
37+
request.method, request.full_url_pattern
38+
)
3739
return self._get_operation_response(operation, response)
3840

3941
def _get_operation_response(self, operation, response):

openapi_core/validation/validators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def parameter_deserializers_factory(self):
4848
def schema_unmarshallers_factory(self):
4949
raise NotImplementedError
5050

51-
def _find_path(self, request):
52-
return self.path_finder.find(request)
51+
def _find_path(self, method, full_url_pattern):
52+
return self.path_finder.find(method, full_url_pattern)
5353

5454
def _get_media_type(self, content, mimetype):
5555
from openapi_core.templating.media_types.finders import MediaTypeFinder

0 commit comments

Comments
 (0)