Skip to content

Commit 1aca1e4

Browse files
committed
Template path length
1 parent 8abed1c commit 1aca1e4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

openapi_core/templating/paths/finders.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from openapi_core.templating.paths.exceptions import (
1010
PathNotFound, OperationNotFound, ServerNotFound,
1111
)
12+
from openapi_core.templating.paths.util import template_path_len
1213

1314

1415
class PathFinder:
@@ -56,7 +57,7 @@ def _get_paths_iter(self, full_url_pattern):
5657
template_paths.append((path, path_result))
5758

5859
# Fewer variables -> more concrete path
59-
for path in sorted(template_paths, key=lambda p: len(p[1].variables)):
60+
for path in sorted(template_paths, key=template_path_len):
6061
yield path
6162

6263
def _get_operations_iter(self, request_method, paths_iter):
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import Tuple
2+
3+
from openapi_core.spec.paths import SpecPath
4+
from openapi_core.templating.datatypes import TemplateResult
5+
6+
7+
def template_path_len(template_path: Tuple[SpecPath, TemplateResult]) -> int:
8+
return len(template_path[1].variables)

0 commit comments

Comments
 (0)