From 349b65ac4da5859af90c0e9cf1904915a0d4e764 Mon Sep 17 00:00:00 2001 From: dawaman43 Date: Tue, 10 Feb 2026 11:44:39 +0300 Subject: [PATCH] Fix implicit path params with converters --- fastapi/utils.py | 3 ++- tests/test_starlette_urlconvertors.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fastapi/utils.py b/fastapi/utils.py index 28c7cdfcc..11082ffa0 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -43,7 +43,8 @@ def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool: def get_path_param_names(path: str) -> set[str]: - return set(re.findall("{(.*?)}", path)) + params = re.findall("{(.*?)}", path) + return {param.split(":", 1)[0] for param in params} _invalid_args_message = ( diff --git a/tests/test_starlette_urlconvertors.py b/tests/test_starlette_urlconvertors.py index 5ef1b819c..0737b51b9 100644 --- a/tests/test_starlette_urlconvertors.py +++ b/tests/test_starlette_urlconvertors.py @@ -19,6 +19,11 @@ def path_convertor(param: str = Path()): return {"path": param} +@app.get("/path-implicit/{param:path}") +def path_convertor_implicit(param: str): + return {"path": param} + + @app.get("/query/") def query_convertor(param: str = Query()): return {"query": param} @@ -50,6 +55,13 @@ def test_route_converters_path(): assert response.json() == {"path": "some/example"} +def test_route_converters_path_implicit(): + # Test path conversion without explicit Path() + response = client.get("/path-implicit/some/example") + assert response.status_code == 200, response.text + assert response.json() == {"path": "some/example"} + + def test_route_converters_query(): # Test query conversion response = client.get("/query", params={"param": "Qué tal!"})