Skip to content

Commit 0ae9ba8

Browse files
authored
Bugfix/starlette root path (#1833)
Fixes the change in behaviour in starlette v0.33 via PR [#2352](encode/starlette#2352)
1 parent 6dc9436 commit 0ae9ba8

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

connexion/middleware/routing.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
3535
scope.get("path_params", {})
3636
)
3737

38-
api_base_path = scope.get("root_path", "")[
39-
len(original_scope.get("root_path", "")) :
40-
]
38+
def get_root_path(scope: Scope) -> str:
39+
return scope.get("route_root_path", scope.get("root_path", ""))
40+
41+
api_base_path = get_root_path(scope)[len(get_root_path(original_scope)) :]
4142

4243
extensions = original_scope.setdefault("extensions", {})
4344
connexion_routing = extensions.setdefault(ROUTING_CONTEXT, {})

connexion/middleware/swagger_ui.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def _base_path_for_prefix(self, request: StarletteRequest) -> str:
5959
"""
6060
returns a modified basePath which includes the incoming root_path.
6161
"""
62-
return request.scope.get("root_path", "").rstrip("/")
62+
return request.scope.get(
63+
"route_root_path", request.scope.get("root_path", "")
64+
).rstrip("/")
6365

6466
def _spec_for_prefix(self, request):
6567
"""

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Jinja2 = ">= 3.0.0"
5353
python-multipart = ">= 0.0.5"
5454
PyYAML = ">= 5.1"
5555
requests = ">= 2.27"
56-
starlette = ">= 0.27, <0.33"
56+
starlette = ">= 0.27"
5757
typing-extensions = ">= 4"
5858
werkzeug = ">= 2.2.1"
5959

tests/test_flask_encoder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ def get_value(data, path):
7575
assert example == "a7b8869c-5f24-4ce0-a5d1-3e44c3663aa9"
7676

7777
res = app_client.get("/v1.0/datetime")
78-
assert res.status_code == 200, f"Error is {res.data}"
78+
assert res.status_code == 200, f"Error is {res.text}"
7979
data = res.json()
8080
assert data == {"value": "2000-01-02T03:04:05.000006Z"}
8181

8282
res = app_client.get("/v1.0/date")
83-
assert res.status_code == 200, f"Error is {res.data}"
83+
assert res.status_code == 200, f"Error is {res.text}"
8484
data = res.json()
8585
assert data == {"value": "2000-01-02"}
8686

8787
res = app_client.get("/v1.0/uuid")
88-
assert res.status_code == 200, f"Error is {res.data}"
88+
assert res.status_code == 200, f"Error is {res.text}"
8989
data = res.json()
9090
assert data == {"value": "e7ff66d0-3ec2-4c4e-bed0-6e4723c24c51"}

0 commit comments

Comments
 (0)