Skip to content

Commit

Permalink
Update root_path access to new starlette behaviour
Browse files Browse the repository at this point in the history
This behaviour was introduced in v0.33 via PR #2352:
https://github.com/encode/starlette/pull/2352/files
  • Loading branch information
Ruwann committed Dec 10, 2023
1 parent e48075e commit 96b7191
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions connexion/middleware/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
scope.get("path_params", {})
)

api_base_path = scope.get("root_path", "")[
len(original_scope.get("root_path", "")) :
api_base_path = scope.get("route_root_path", scope.get("root_path", ""))[
len(
original_scope.get(
"route_root_path", original_scope.get("root_path", "")
)
) :
]

extensions = original_scope.setdefault("extensions", {})
Expand Down
4 changes: 3 additions & 1 deletion connexion/middleware/swagger_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def _base_path_for_prefix(self, request: StarletteRequest) -> str:
"""
returns a modified basePath which includes the incoming root_path.
"""
return request.scope.get("root_path", "").rstrip("/")
return request.scope.get(
"route_root_path", request.scope.get("root_path", "")
).rstrip("/")

def _spec_for_prefix(self, request):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Jinja2 = ">= 3.0.0"
python-multipart = ">= 0.0.5"
PyYAML = ">= 5.1"
requests = ">= 2.27"
starlette = ">= 0.27, <0.33"
starlette = ">= 0.27"
typing-extensions = ">= 4"
werkzeug = ">= 2.2.1"

Expand Down

0 comments on commit 96b7191

Please sign in to comment.