Skip to content

Commit

Permalink
♻️ Refactor include_router to mount sub-routers
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Apr 13, 2022
1 parent 26f725d commit edcae91
Show file tree
Hide file tree
Showing 5 changed files with 606 additions and 159 deletions.
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
Loading

0 comments on commit edcae91

Please sign in to comment.