mirror of https://github.com/tiangolo/fastapi.git
Add args/kwargs to rest of the methods and fix test
This commit is contained in:
parent
0022fc77c0
commit
d5548ac802
|
|
@ -2226,7 +2226,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -2545,6 +2544,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP POST operation.
|
||||
|
|
@ -2590,6 +2591,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def delete(
|
||||
|
|
@ -2604,7 +2607,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -2923,6 +2925,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP DELETE operation.
|
||||
|
|
@ -2963,6 +2967,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def options(
|
||||
|
|
@ -2977,7 +2983,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -3296,6 +3301,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP OPTIONS operation.
|
||||
|
|
@ -3336,6 +3343,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def head(
|
||||
|
|
@ -3350,7 +3359,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -3669,6 +3677,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP HEAD operation.
|
||||
|
|
@ -3709,6 +3719,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def patch(
|
||||
|
|
@ -3723,7 +3735,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -4042,6 +4053,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP PATCH operation.
|
||||
|
|
@ -4087,6 +4100,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def trace(
|
||||
|
|
@ -4101,7 +4116,6 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -4420,6 +4434,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP TRACE operation.
|
||||
|
|
@ -4460,6 +4476,8 @@ class FastAPI(Starlette):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def websocket_route(
|
||||
|
|
|
|||
|
|
@ -984,6 +984,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
return func
|
||||
|
||||
|
|
@ -1089,7 +1091,6 @@ class APIRouter(routing.Router):
|
|||
def include_router(
|
||||
self,
|
||||
router: Annotated["APIRouter", Doc("The `APIRouter` to include.")],
|
||||
*,
|
||||
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
|
||||
tags: Annotated[
|
||||
Optional[List[Union[str, Enum]]],
|
||||
|
|
@ -1197,6 +1198,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""
|
||||
Include another `APIRouter` in the same current `APIRouter`.
|
||||
|
|
@ -1295,6 +1298,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=current_callbacks,
|
||||
openapi_extra=route.openapi_extra,
|
||||
generate_unique_id_function=current_generate_unique_id,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
elif isinstance(route, routing.Route):
|
||||
methods = list(route.methods or [])
|
||||
|
|
@ -1702,6 +1707,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def put(
|
||||
|
|
@ -1716,7 +1723,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -2035,6 +2041,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP PUT operation.
|
||||
|
|
@ -2084,6 +2092,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def post(
|
||||
|
|
@ -2098,7 +2108,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -2417,6 +2426,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP POST operation.
|
||||
|
|
@ -2466,6 +2477,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def delete(
|
||||
|
|
@ -2480,7 +2493,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -2799,6 +2811,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP DELETE operation.
|
||||
|
|
@ -2843,6 +2857,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def options(
|
||||
|
|
@ -2857,7 +2873,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -3176,6 +3191,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP OPTIONS operation.
|
||||
|
|
@ -3220,6 +3237,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def head(
|
||||
|
|
@ -3234,7 +3253,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -3553,6 +3571,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP HEAD operation.
|
||||
|
|
@ -3602,6 +3622,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def patch(
|
||||
|
|
@ -3616,7 +3638,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -3935,6 +3956,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP PATCH operation.
|
||||
|
|
@ -3984,6 +4007,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def trace(
|
||||
|
|
@ -3998,7 +4023,6 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
],
|
||||
*,
|
||||
response_model: Annotated[
|
||||
Any,
|
||||
Doc(
|
||||
|
|
@ -4317,6 +4341,8 @@ class APIRouter(routing.Router):
|
|||
"""
|
||||
),
|
||||
] = Default(generate_unique_id),
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Add a *path operation* using an HTTP TRACE operation.
|
||||
|
|
@ -4366,6 +4392,8 @@ class APIRouter(routing.Router):
|
|||
callbacks=callbacks,
|
||||
openapi_extra=openapi_extra,
|
||||
generate_unique_id_function=generate_unique_id_function,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@deprecated(
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
import inspect
|
||||
|
||||
import pytest
|
||||
|
||||
from fastapi import APIRouter, FastAPI
|
||||
|
||||
method_names = ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
|
||||
|
||||
|
||||
def test_signatures_consistency():
|
||||
base_sig = inspect.signature(APIRouter.get)
|
||||
for method_name in method_names:
|
||||
@pytest.mark.parametrize('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):
|
||||
router_method = getattr(APIRouter, method_name)
|
||||
app_method = getattr(FastAPI, method_name)
|
||||
router_sig = inspect.signature(router_method)
|
||||
app_sig = inspect.signature(app_method)
|
||||
param: inspect.Parameter
|
||||
for key, param in base_sig.parameters.items():
|
||||
key, param = sig_param
|
||||
router_param: inspect.Parameter = router_sig.parameters[key]
|
||||
app_param: inspect.Parameter = app_sig.parameters[key]
|
||||
assert param.annotation == router_param.annotation
|
||||
|
|
|
|||
Loading…
Reference in New Issue