File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,5 +95,5 @@ def _get_fastapi_route(fastapi_app: FastAPI, scope) -> Optional[Route]:
9595 # and return the route name if found.
9696 match , child_scope = route .matches (scope )
9797 if match == Match .FULL :
98- return child_scope [ "route" ]
98+ return child_scope . get ( "route" )
9999 return None
Original file line number Diff line number Diff line change 55from google .cloud .sqlcommenter .fastapi import (
66 SQLCommenterMiddleware , get_fastapi_info ,
77)
8+ from starlette .applications import Starlette
89from starlette .exceptions import HTTPException as StarletteHTTPException
10+ from starlette .routing import Route
911
1012app = FastAPI (title = "SQLCommenter" )
1113
@@ -28,3 +30,15 @@ async def custom_http_exception_handler(request, exc):
2830 status_code = status .HTTP_404_NOT_FOUND ,
2931 content = get_fastapi_info (),
3032 )
33+
34+
35+ def starlette_endpoint (_ ):
36+ return JSONResponse ({"from" : "starlette" })
37+
38+
39+ starlette_subapi = Starlette (routes = [
40+ Route ("/" , starlette_endpoint ),
41+ ])
42+
43+
44+ app .mount ("/starlette" , starlette_subapi )
Original file line number Diff line number Diff line change @@ -52,3 +52,13 @@ def test_get_fastapi_info_in_404_error_context(client):
5252
5353def test_get_fastapi_info_outside_request_context (client ):
5454 assert get_fastapi_info () == {}
55+
56+
57+ def test_get_openapi_does_not_throw_an_error (client ):
58+ resp = client .get (app .docs_url )
59+ assert resp .status_code == 200
60+
61+
62+ def test_get_starlette_endpoints_does_not_throw_an_error (client ):
63+ resp = client .get ("/starlette" )
64+ assert resp .status_code == 200
You can’t perform that action at this time.
0 commit comments