Fail to parse a nested url route
igormaraujo opened this issue · 0 comments
igormaraujo commented
The Problem
I'm using the openapi-tester with a file schema.yml loader, when a test a nested router (drf-nested-routers), for example, /v1/matchs/1/maps/1/playerStats/
. I get a error of undocumented route. At the error message, we can see that the pks at the path was wrong position parsed.
The Error Message
======================================================================
ERROR: test_list_all_playerStats (game.tests.test_view_playerStats.PlayerStatsViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/miniconda3/envs/hintclub-api/lib/python3.7/site-packages/openapi_tester/schema_tester.py", line 82, in get_key_value
return schema[key]
KeyError: '/v1/matchs/{map_pk}/maps/{match_pk}/playerStats/'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/***********/Documents/vscode_workspace/***********/game/tests/test_view_playerStats.py", line 124, in test_list_all_playerStats
self.assertResponse(response)
File "/Users/***********/Documents/vscode_workspace/***********/common/tests.py", line 14, in assertResponse
schema_tester.validate_response(response=response, **kwargs)
File "/opt/miniconda3/envs/hintclub-api/lib/python3.7/site-packages/openapi_tester/schema_tester.py", line 349, in validate_response
response_schema = self.get_response_schema_section(response)
File "/opt/miniconda3/envs/hintclub-api/lib/python3.7/site-packages/openapi_tester/schema_tester.py", line 124, in get_response_schema_section
f"\n\nUndocumented route {parameterized_path}.\n\nDocumented routes: " + "\n\t• ".join(paths_object.keys()),
File "/opt/miniconda3/envs/hintclub-api/lib/python3.7/site-packages/openapi_tester/schema_tester.py", line 86, in get_key_value
) from e
openapi_tester.exceptions.UndocumentedSchemaSectionError: Error: Unsuccessfully tried to index the OpenAPI schema by `/v1/matchs/{map_pk}/maps/{match_pk}/playerStats/`.
Undocumented route /v1/matchs/{map_pk}/maps/{match_pk}/playerStats/.
Documented routes: /v1/matchs/{match_pk}/maps/{map_pk}/playerStats/
The Possible Solution
At line 137 is executed a right string search rfind
, so the dictionary should be reversed like this reversed(list(resolved_route.kwargs.items())
.
drf-openapi-tester/openapi_tester/loaders.py
Lines 118 to 148 in e2bd0ab