From 96b7191944abb3474235bbc0592a81b23678184b Mon Sep 17 00:00:00 2001 From: Ruwan Date: Sun, 10 Dec 2023 18:32:00 +0100 Subject: [PATCH] Update root_path access to new starlette behaviour This behaviour was introduced in v0.33 via PR #2352: https://github.com/encode/starlette/pull/2352/files --- connexion/middleware/routing.py | 8 ++++++-- connexion/middleware/swagger_ui.py | 4 +++- pyproject.toml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/connexion/middleware/routing.py b/connexion/middleware/routing.py index 7f4be932f..0f0e0e95b 100644 --- a/connexion/middleware/routing.py +++ b/connexion/middleware/routing.py @@ -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", {}) diff --git a/connexion/middleware/swagger_ui.py b/connexion/middleware/swagger_ui.py index 90d67fa45..a9bded0fe 100644 --- a/connexion/middleware/swagger_ui.py +++ b/connexion/middleware/swagger_ui.py @@ -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): """ diff --git a/pyproject.toml b/pyproject.toml index 5fed8b47d..2ac6c6057 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"