Skip to content

Commit 44d3fd3

Browse files
author
Sebastian Mainberger
committed
Bug: Prioritize concrete paths over template paths.
1 parent 0aeb144 commit 44d3fd3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

openapi_core/templating/paths/finders.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def find(self, request):
3939
raise ServerNotFound(request.full_url_pattern)
4040

4141
def _get_paths_iter(self, full_url_pattern):
42+
template_paths = []
4243
for path_pattern, path in iteritems(self.spec.paths):
43-
# simple path
44+
# simple path. Return right away since it is always the most concrete
4445
if full_url_pattern.endswith(path_pattern):
4546
path_result = TemplateResult(path_pattern, {})
4647
yield (path, path_result)
@@ -49,7 +50,11 @@ def _get_paths_iter(self, full_url_pattern):
4950
result = search(path_pattern, full_url_pattern)
5051
if result:
5152
path_result = TemplateResult(path_pattern, result.named)
52-
yield (path, path_result)
53+
template_paths.append((path, path_result))
54+
55+
# Fewer variables -> more concrete path
56+
for path in sorted(template_paths, key=lambda p: len(p[1].variables)):
57+
yield path
5358

5459
def _get_operations_iter(self, request_method, paths_iter):
5560
for path, path_result in paths_iter:

0 commit comments

Comments
 (0)