Browse Source

Merge 8618925db2 into 1d434dec47

pull/11050/merge
Aleksei Kotenko 4 days ago
committed by GitHub
parent
commit
2a1c9237bd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 40
      fastapi/applications.py
  2. 79
      fastapi/routing.py
  3. 15
      tests/test_operations_signatures.py

40
fastapi/applications.py

@ -1469,7 +1469,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -1788,6 +1788,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.
@ -1806,6 +1807,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,
@ -1828,6 +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,
) )
def put( def put(
@ -1842,7 +1845,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2161,6 +2164,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.
@ -2184,6 +2188,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,
@ -2206,6 +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,
) )
def post( def post(
@ -2220,7 +2226,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2539,6 +2545,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.
@ -2562,6 +2569,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,
@ -2584,6 +2592,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(
@ -2598,7 +2607,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2917,6 +2926,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.
@ -2935,6 +2945,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,
@ -2957,6 +2968,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(
@ -2971,7 +2983,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -3290,6 +3302,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.
@ -3308,6 +3321,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,
@ -3330,6 +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,
) )
def head( def head(
@ -3344,7 +3359,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -3663,6 +3678,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.
@ -3681,6 +3697,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,
@ -3703,6 +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,
) )
def patch( def patch(
@ -3717,7 +3735,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -4036,6 +4054,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.
@ -4081,6 +4100,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(
@ -4095,7 +4116,7 @@ class FastAPI(Starlette):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -4414,6 +4435,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.
@ -4432,6 +4454,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,
@ -4454,6 +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,
) )
def websocket_route( def websocket_route(

79
fastapi/routing.py

@ -430,7 +430,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,
@ -459,6 +459,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
@ -621,7 +622,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]]],
@ -833,6 +834,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,
@ -882,7 +884,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,
@ -911,6 +913,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 {}
@ -932,7 +935,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,
@ -957,13 +961,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,
@ -989,11 +994,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,
@ -1017,6 +1024,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
@ -1122,7 +1130,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]]],
@ -1230,6 +1238,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`.
@ -1302,6 +1311,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,
@ -1328,6 +1338,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 [])
@ -1375,7 +1386,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -1694,6 +1705,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.
@ -1714,7 +1726,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,
@ -1738,6 +1751,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(
@ -1752,7 +1766,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2071,6 +2085,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.
@ -2096,7 +2111,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,
@ -2120,6 +2136,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(
@ -2134,7 +2151,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2453,6 +2470,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.
@ -2478,7 +2496,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,
@ -2502,6 +2521,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(
@ -2516,7 +2536,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -2835,6 +2855,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.
@ -2855,7 +2876,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,
@ -2879,6 +2901,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(
@ -2893,7 +2916,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -3212,6 +3235,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.
@ -3232,7 +3256,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,
@ -3256,6 +3281,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(
@ -3270,7 +3296,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -3589,6 +3615,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.
@ -3614,7 +3641,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,
@ -3638,6 +3666,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(
@ -3652,7 +3681,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -3971,6 +4000,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.
@ -3996,7 +4026,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,
@ -4020,6 +4051,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(
@ -4034,7 +4066,7 @@ class APIRouter(routing.Router):
""" """
), ),
], ],
*, *args: Any,
response_model: Annotated[ response_model: Annotated[
Any, Any,
Doc( Doc(
@ -4353,6 +4385,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.
@ -4378,7 +4411,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,
@ -4402,6 +4436,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(

15
tests/test_operations_signatures.py

@ -1,19 +1,22 @@
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(
"sig_param", inspect.signature(APIRouter.get).parameters.items()
)
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)
router_sig = inspect.signature(router_method) router_sig = inspect.signature(router_method)
app_sig = inspect.signature(app_method) app_sig = inspect.signature(app_method)
param: inspect.Parameter param: inspect.Parameter
for key, param in base_sig.parameters.items(): key, param = sig_param
router_param: inspect.Parameter = router_sig.parameters[key] router_param: inspect.Parameter = router_sig.parameters[key]
app_param: inspect.Parameter = app_sig.parameters[key] app_param: inspect.Parameter = app_sig.parameters[key]
assert param.annotation == router_param.annotation assert param.annotation == router_param.annotation

Loading…
Cancel
Save