Skip to content

Commit d553e37

Browse files
committed
Paths finder paths order fix
1 parent 187b3d6 commit d553e37

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

openapi_core/templating/paths/finders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _get_servers_iter(self, full_url_pattern, ooperations_iter):
6767
if server_url.endswith('/'):
6868
server_url = server_url[:-1]
6969
# simple path
70-
if server_url_pattern.startswith(server_url):
70+
if server_url_pattern == server_url:
7171
server_result = TemplateResult(server.url, {})
7272
yield (
7373
path, operation, server,

tests/unit/templating/test_paths_finders.py

+45
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,48 @@ class TestPathVariableServerValid(
390390
BaseTestVariableValid, BaseTestPathServer,
391391
BaseTestSimplePath, BaseTestVariableServer):
392392
pass
393+
394+
395+
class TestSimilarPaths(
396+
BaseTestSpecServer, BaseTestSimpleServer):
397+
398+
path_name = '/tokens'
399+
400+
@pytest.fixture
401+
def operation_2(self):
402+
return Operation('get', '/keys/{id}/tokens', {}, {})
403+
404+
@pytest.fixture
405+
def operations_2(self, operation_2):
406+
return {
407+
'get': operation_2,
408+
}
409+
410+
@pytest.fixture
411+
def path(self, operations):
412+
return Path('/tokens', operations)
413+
414+
@pytest.fixture
415+
def path_2(self, operations_2):
416+
return Path('/keys/{id}/tokens', operations_2)
417+
418+
@pytest.fixture
419+
def paths(self, path, path_2):
420+
return {
421+
path.name: path,
422+
path_2.name: path_2,
423+
}
424+
425+
def test_valid(self, finder, path_2, operation_2, server):
426+
token_id = '123'
427+
request_uri = '/keys/{0}/tokens'.format(token_id)
428+
request = MockRequest(
429+
'http://petstore.swagger.io', 'get', request_uri)
430+
431+
result = finder.find(request)
432+
433+
path_result = TemplateResult(path_2.name, {'id': token_id})
434+
server_result = TemplateResult(self.server_url, {})
435+
assert result == (
436+
path_2, operation_2, server, path_result, server_result,
437+
)

0 commit comments

Comments
 (0)