Browse Source

Reformat

pull/11050/head
Alexey Kotenko 1 year ago
parent
commit
20a84fdf5f
  1. 26
      fastapi/applications.py
  2. 8
      fastapi/routing.py
  3. 8
      tests/test_operations_signatures.py

26
fastapi/applications.py

@ -1028,6 +1028,7 @@ class FastAPI(Starlette):
self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False) self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False)
if self.swagger_ui_oauth2_redirect_url: if self.swagger_ui_oauth2_redirect_url:
async def swagger_ui_redirect(req: Request) -> HTMLResponse: async def swagger_ui_redirect(req: Request) -> HTMLResponse:
return get_swagger_ui_oauth2_redirect_html() return get_swagger_ui_oauth2_redirect_html()
@ -1037,6 +1038,7 @@ class FastAPI(Starlette):
include_in_schema=False, include_in_schema=False,
) )
if self.openapi_url and self.redoc_url: if self.openapi_url and self.redoc_url:
async def redoc_html(req: Request) -> HTMLResponse: async def redoc_html(req: Request) -> HTMLResponse:
root_path = req.scope.get("root_path", "").rstrip("/") root_path = req.scope.get("root_path", "").rstrip("/")
openapi_url = root_path + self.openapi_url openapi_url = root_path + self.openapi_url
@ -1828,7 +1830,7 @@ class FastAPI(Starlette):
callbacks=callbacks, callbacks=callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
**kwargs **kwargs,
) )
def put( def put(
@ -2162,7 +2164,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP PUT operation. Add a *path operation* using an HTTP PUT operation.
@ -2209,7 +2211,7 @@ class FastAPI(Starlette):
callbacks=callbacks, callbacks=callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
**kwargs **kwargs,
) )
def post( def post(
@ -2543,7 +2545,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP POST operation. Add a *path operation* using an HTTP POST operation.
@ -2924,7 +2926,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP DELETE operation. Add a *path operation* using an HTTP DELETE operation.
@ -3300,7 +3302,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP OPTIONS operation. Add a *path operation* using an HTTP OPTIONS operation.
@ -3342,7 +3344,7 @@ class FastAPI(Starlette):
callbacks=callbacks, callbacks=callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
**kwargs **kwargs,
) )
def head( def head(
@ -3676,7 +3678,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP HEAD operation. Add a *path operation* using an HTTP HEAD operation.
@ -3718,7 +3720,7 @@ class FastAPI(Starlette):
callbacks=callbacks, callbacks=callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
**kwargs **kwargs,
) )
def patch( def patch(
@ -4052,7 +4054,7 @@ class FastAPI(Starlette):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP PATCH operation. Add a *path operation* using an HTTP PATCH operation.
@ -4099,7 +4101,7 @@ class FastAPI(Starlette):
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
# *args, # *args,
**kwargs **kwargs,
) )
def trace( def trace(
@ -4475,7 +4477,7 @@ class FastAPI(Starlette):
callbacks=callbacks, callbacks=callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=generate_unique_id_function, generate_unique_id_function=generate_unique_id_function,
**kwargs **kwargs,
) )
def websocket_route( def websocket_route(

8
fastapi/routing.py

@ -796,7 +796,7 @@ class APIRouter(routing.Router):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> None: ) -> None:
super().__init__( super().__init__(
routes=routes, routes=routes,
@ -923,7 +923,7 @@ class APIRouter(routing.Router):
callbacks=current_callbacks, callbacks=current_callbacks,
openapi_extra=openapi_extra, openapi_extra=openapi_extra,
generate_unique_id_function=current_generate_unique_id, generate_unique_id_function=current_generate_unique_id,
**kwargs **kwargs,
) )
self.routes.append(route) self.routes.append(route)
@ -1300,7 +1300,7 @@ class APIRouter(routing.Router):
callbacks=current_callbacks, callbacks=current_callbacks,
openapi_extra=route.openapi_extra, openapi_extra=route.openapi_extra,
generate_unique_id_function=current_generate_unique_id, generate_unique_id_function=current_generate_unique_id,
**kwargs **kwargs,
) )
elif isinstance(route, routing.Route): elif isinstance(route, routing.Route):
methods = list(route.methods or []) methods = list(route.methods or [])
@ -2428,7 +2428,7 @@ class APIRouter(routing.Router):
""" """
), ),
] = Default(generate_unique_id), ] = Default(generate_unique_id),
**kwargs: Any **kwargs: Any,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Add a *path operation* using an HTTP POST operation. Add a *path operation* using an HTTP POST operation.

8
tests/test_operations_signatures.py

@ -4,8 +4,12 @@ import pytest
from fastapi import APIRouter, FastAPI from fastapi import APIRouter, FastAPI
@pytest.mark.parametrize('method_name', ["get", "put", "post", "delete", "options", "head", "patch", "trace"]) @pytest.mark.parametrize(
@pytest.mark.parametrize('sig_param', inspect.signature(APIRouter.get).parameters.items()) "method_name", ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
)
@pytest.mark.parametrize(
"sig_param", inspect.signature(APIRouter.get).parameters.items()
)
def test_signatures_consistency(method_name, sig_param): def test_signatures_consistency(method_name, sig_param):
router_method = getattr(APIRouter, method_name) router_method = getattr(APIRouter, method_name)
app_method = getattr(FastAPI, method_name) app_method = getattr(FastAPI, method_name)

Loading…
Cancel
Save