Add `router_class` param

This commit is contained in:
Alexey Kotenko 2024-01-30 14:41:55 +00:00
parent efee7a407d
commit 25419b7c39
1 changed files with 13 additions and 2 deletions

View File

@ -810,6 +810,17 @@ class FastAPI(Starlette):
"""
),
] = True,
router_class: Annotated[
Type[routing.APIRouter],
Doc(
"""
The default router class to be used.
Read more in the
[FastAPI docs for Custom Router](Bigger Applications - Multiple Files).
"""
),
] = routing.APIRouter,
**extra: Annotated[
Any,
Doc(
@ -893,7 +904,7 @@ class FastAPI(Starlette):
[FastAPI docs for OpenAPI Webhooks](https://fastapi.tiangolo.com/advanced/openapi-webhooks/).
"""
),
] = webhooks or routing.APIRouter()
] = webhooks or router_class()
self.root_path = root_path or openapi_prefix
self.state: Annotated[
State,
@ -929,7 +940,7 @@ class FastAPI(Starlette):
"""
),
] = {}
self.router: routing.APIRouter = routing.APIRouter(
self.router: routing.APIRouter = router_class(
routes=routes,
redirect_slashes=redirect_slashes,
dependency_overrides_provider=self,