Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor include_router to mount sub-routers #4794

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions fastapi/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def __init__(
self.middleware_stack: ASGIApp = self.build_middleware_stack()
self.setup()

@property
def routes(self) -> List[BaseRoute]:
return list(self.router.iter_all_routes())

def build_middleware_stack(self) -> ASGIApp:
# Duplicate/override from Starlette to add AsyncExitStackMiddleware
# inside of ExceptionMiddleware, inside of custom user middlewares
Expand Down
6 changes: 3 additions & 3 deletions fastapi/openapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def generate_operation_id(
)
if route.operation_id:
return route.operation_id
path: str = route.path_format
path: str = route._route_full_path_format
return generate_operation_id_for_path(name=route.name, path=path, method=method)


Expand Down Expand Up @@ -243,7 +243,7 @@ def get_openapi_path(
model_name_map=model_name_map,
operation_ids=operation_ids,
)
callbacks[callback.name] = {callback.path: cb_path}
callbacks[callback.name] = {callback._route_full_path: cb_path}
operation["callbacks"] = callbacks
if route.status_code is not None:
status_code = str(route.status_code)
Expand Down Expand Up @@ -422,7 +422,7 @@ def get_openapi(
if result:
path, security_schemes, path_definitions = result
if path:
paths.setdefault(route.path_format, {}).update(path)
paths.setdefault(route._route_full_path_format, {}).update(path)
if security_schemes:
components.setdefault("securitySchemes", {}).update(
security_schemes
Expand Down