mirror of https://github.com/tiangolo/fastapi.git
Merge 8618925db2 into 272204c0c7
This commit is contained in:
commit
d813b9929e
|
|
@ -1554,7 +1554,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -1873,6 +1873,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||||
"""
|
"""
|
||||||
Add a *path operation* using an HTTP GET operation.
|
Add a *path operation* using an HTTP GET operation.
|
||||||
|
|
@ -1891,6 +1892,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.get(
|
return self.router.get(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -1913,6 +1915,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def put(
|
def put(
|
||||||
|
|
@ -1927,7 +1930,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -2246,6 +2249,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -2269,6 +2273,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.put(
|
return self.router.put(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -2291,6 +2296,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def post(
|
def post(
|
||||||
|
|
@ -2305,7 +2311,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -2624,6 +2630,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -2647,6 +2654,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.post(
|
return self.router.post(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -2669,6 +2677,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(
|
def delete(
|
||||||
|
|
@ -2683,7 +2692,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -3002,6 +3011,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -3020,6 +3030,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.delete(
|
return self.router.delete(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3042,6 +3053,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def options(
|
def options(
|
||||||
|
|
@ -3056,7 +3068,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -3375,6 +3387,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -3393,6 +3406,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.options(
|
return self.router.options(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3415,6 +3429,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def head(
|
def head(
|
||||||
|
|
@ -3429,7 +3444,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -3748,6 +3763,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -3766,6 +3782,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.head(
|
return self.router.head(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3788,6 +3805,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def patch(
|
def patch(
|
||||||
|
|
@ -3802,7 +3820,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -4121,6 +4139,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -4166,6 +4185,8 @@ 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,
|
||||||
|
# *args,
|
||||||
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
def trace(
|
def trace(
|
||||||
|
|
@ -4180,7 +4201,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -4499,6 +4520,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||||
"""
|
"""
|
||||||
Add a *path operation* using an HTTP TRACE operation.
|
Add a *path operation* using an HTTP TRACE operation.
|
||||||
|
|
@ -4517,6 +4539,7 @@ class FastAPI(Starlette):
|
||||||
"""
|
"""
|
||||||
return self.router.trace(
|
return self.router.trace(
|
||||||
path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -4539,6 +4562,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def websocket_route(
|
def websocket_route(
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@ class APIRoute(routing.Route):
|
||||||
self,
|
self,
|
||||||
path: str,
|
path: str,
|
||||||
endpoint: Callable[..., Any],
|
endpoint: Callable[..., Any],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Any = Default(None),
|
response_model: Any = Default(None),
|
||||||
status_code: Optional[int] = None,
|
status_code: Optional[int] = None,
|
||||||
tags: Optional[List[Union[str, Enum]]] = None,
|
tags: Optional[List[Union[str, Enum]]] = None,
|
||||||
|
|
@ -591,6 +591,7 @@ class APIRoute(routing.Route):
|
||||||
generate_unique_id_function: Union[
|
generate_unique_id_function: Union[
|
||||||
Callable[["APIRoute"], str], DefaultPlaceholder
|
Callable[["APIRoute"], str], DefaultPlaceholder
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.endpoint = endpoint
|
self.endpoint = endpoint
|
||||||
|
|
@ -755,7 +756,7 @@ class APIRouter(routing.Router):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*args: Any,
|
||||||
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
|
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
|
||||||
tags: Annotated[
|
tags: Annotated[
|
||||||
Optional[List[Union[str, Enum]]],
|
Optional[List[Union[str, Enum]]],
|
||||||
|
|
@ -967,6 +968,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
routes=routes,
|
routes=routes,
|
||||||
|
|
@ -1016,7 +1018,7 @@ class APIRouter(routing.Router):
|
||||||
self,
|
self,
|
||||||
path: str,
|
path: str,
|
||||||
endpoint: Callable[..., Any],
|
endpoint: Callable[..., Any],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Any = Default(None),
|
response_model: Any = Default(None),
|
||||||
status_code: Optional[int] = None,
|
status_code: Optional[int] = None,
|
||||||
tags: Optional[List[Union[str, Enum]]] = None,
|
tags: Optional[List[Union[str, Enum]]] = None,
|
||||||
|
|
@ -1045,6 +1047,7 @@ class APIRouter(routing.Router):
|
||||||
generate_unique_id_function: Union[
|
generate_unique_id_function: Union[
|
||||||
Callable[[APIRoute], str], DefaultPlaceholder
|
Callable[[APIRoute], str], DefaultPlaceholder
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
route_class = route_class_override or self.route_class
|
route_class = route_class_override or self.route_class
|
||||||
responses = responses or {}
|
responses = responses or {}
|
||||||
|
|
@ -1066,7 +1069,8 @@ class APIRouter(routing.Router):
|
||||||
)
|
)
|
||||||
route = route_class(
|
route = route_class(
|
||||||
self.prefix + path,
|
self.prefix + path,
|
||||||
endpoint=endpoint,
|
endpoint,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=current_tags,
|
tags=current_tags,
|
||||||
|
|
@ -1091,13 +1095,14 @@ 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,
|
||||||
)
|
)
|
||||||
self.routes.append(route)
|
self.routes.append(route)
|
||||||
|
|
||||||
def api_route(
|
def api_route(
|
||||||
self,
|
self,
|
||||||
path: str,
|
path: str,
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Any = Default(None),
|
response_model: Any = Default(None),
|
||||||
status_code: Optional[int] = None,
|
status_code: Optional[int] = None,
|
||||||
tags: Optional[List[Union[str, Enum]]] = None,
|
tags: Optional[List[Union[str, Enum]]] = None,
|
||||||
|
|
@ -1123,11 +1128,13 @@ class APIRouter(routing.Router):
|
||||||
generate_unique_id_function: Callable[[APIRoute], str] = Default(
|
generate_unique_id_function: Callable[[APIRoute], str] = Default(
|
||||||
generate_unique_id
|
generate_unique_id
|
||||||
),
|
),
|
||||||
|
**kwargs: Any,
|
||||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||||
def decorator(func: DecoratedCallable) -> DecoratedCallable:
|
def decorator(func: DecoratedCallable) -> DecoratedCallable:
|
||||||
self.add_api_route(
|
self.add_api_route(
|
||||||
path,
|
path,
|
||||||
func,
|
func,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -1151,6 +1158,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
@ -1256,7 +1264,7 @@ class APIRouter(routing.Router):
|
||||||
def include_router(
|
def include_router(
|
||||||
self,
|
self,
|
||||||
router: Annotated["APIRouter", Doc("The `APIRouter` to include.")],
|
router: Annotated["APIRouter", Doc("The `APIRouter` to include.")],
|
||||||
*,
|
*args: Any,
|
||||||
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
|
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
|
||||||
tags: Annotated[
|
tags: Annotated[
|
||||||
Optional[List[Union[str, Enum]]],
|
Optional[List[Union[str, Enum]]],
|
||||||
|
|
@ -1364,6 +1372,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Include another `APIRouter` in the same current `APIRouter`.
|
Include another `APIRouter` in the same current `APIRouter`.
|
||||||
|
|
@ -1436,6 +1445,7 @@ class APIRouter(routing.Router):
|
||||||
self.add_api_route(
|
self.add_api_route(
|
||||||
prefix + route.path,
|
prefix + route.path,
|
||||||
route.endpoint,
|
route.endpoint,
|
||||||
|
*args,
|
||||||
response_model=route.response_model,
|
response_model=route.response_model,
|
||||||
status_code=route.status_code,
|
status_code=route.status_code,
|
||||||
tags=current_tags,
|
tags=current_tags,
|
||||||
|
|
@ -1462,6 +1472,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,
|
||||||
)
|
)
|
||||||
elif isinstance(route, routing.Route):
|
elif isinstance(route, routing.Route):
|
||||||
methods = list(route.methods or [])
|
methods = list(route.methods or [])
|
||||||
|
|
@ -1509,7 +1520,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -1828,6 +1839,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||||
"""
|
"""
|
||||||
Add a *path operation* using an HTTP GET operation.
|
Add a *path operation* using an HTTP GET operation.
|
||||||
|
|
@ -1848,7 +1860,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -1872,6 +1885,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def put(
|
def put(
|
||||||
|
|
@ -1886,7 +1900,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -2205,6 +2219,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -2230,7 +2245,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -2254,6 +2270,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def post(
|
def post(
|
||||||
|
|
@ -2268,7 +2285,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -2587,6 +2604,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -2612,7 +2630,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -2636,6 +2655,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(
|
def delete(
|
||||||
|
|
@ -2650,7 +2670,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -2969,6 +2989,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -2989,7 +3010,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3013,6 +3035,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def options(
|
def options(
|
||||||
|
|
@ -3027,7 +3050,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -3346,6 +3369,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -3366,7 +3390,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3390,6 +3415,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def head(
|
def head(
|
||||||
|
|
@ -3404,7 +3430,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -3723,6 +3749,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -3748,7 +3775,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -3772,6 +3800,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def patch(
|
def patch(
|
||||||
|
|
@ -3786,7 +3815,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -4105,6 +4134,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**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.
|
||||||
|
|
@ -4130,7 +4160,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -4154,6 +4185,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
def trace(
|
def trace(
|
||||||
|
|
@ -4168,7 +4200,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
*,
|
*args: Any,
|
||||||
response_model: Annotated[
|
response_model: Annotated[
|
||||||
Any,
|
Any,
|
||||||
Doc(
|
Doc(
|
||||||
|
|
@ -4487,6 +4519,7 @@ class APIRouter(routing.Router):
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
] = Default(generate_unique_id),
|
] = Default(generate_unique_id),
|
||||||
|
**kwargs: Any,
|
||||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||||
"""
|
"""
|
||||||
Add a *path operation* using an HTTP TRACE operation.
|
Add a *path operation* using an HTTP TRACE operation.
|
||||||
|
|
@ -4512,7 +4545,8 @@ class APIRouter(routing.Router):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
return self.api_route(
|
return self.api_route(
|
||||||
path=path,
|
path,
|
||||||
|
*args,
|
||||||
response_model=response_model,
|
response_model=response_model,
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
|
|
@ -4536,6 +4570,7 @@ class APIRouter(routing.Router):
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
@deprecated(
|
@deprecated(
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,25 @@
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
import pytest
|
||||||
from fastapi import APIRouter, FastAPI
|
from fastapi import APIRouter, FastAPI
|
||||||
|
|
||||||
method_names = ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
def test_signatures_consistency():
|
"method_name", ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
|
||||||
base_sig = inspect.signature(APIRouter.get)
|
)
|
||||||
for method_name in method_names:
|
@pytest.mark.parametrize(
|
||||||
router_method = getattr(APIRouter, method_name)
|
"sig_param", inspect.signature(APIRouter.get).parameters.items()
|
||||||
app_method = getattr(FastAPI, method_name)
|
)
|
||||||
router_sig = inspect.signature(router_method)
|
def test_signatures_consistency(method_name, sig_param):
|
||||||
app_sig = inspect.signature(app_method)
|
router_method = getattr(APIRouter, method_name)
|
||||||
param: inspect.Parameter
|
app_method = getattr(FastAPI, method_name)
|
||||||
for key, param in base_sig.parameters.items():
|
router_sig = inspect.signature(router_method)
|
||||||
router_param: inspect.Parameter = router_sig.parameters[key]
|
app_sig = inspect.signature(app_method)
|
||||||
app_param: inspect.Parameter = app_sig.parameters[key]
|
param: inspect.Parameter
|
||||||
assert param.annotation == router_param.annotation
|
key, param = sig_param
|
||||||
assert param.annotation == app_param.annotation
|
router_param: inspect.Parameter = router_sig.parameters[key]
|
||||||
assert param.default == router_param.default
|
app_param: inspect.Parameter = app_sig.parameters[key]
|
||||||
assert param.default == app_param.default
|
assert param.annotation == router_param.annotation
|
||||||
|
assert param.annotation == app_param.annotation
|
||||||
|
assert param.default == router_param.default
|
||||||
|
assert param.default == app_param.default
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue