setup() — fastapi Function Reference
Architecture documentation for the setup() function in applications.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d["setup()"] 587454b3_6db6_011f_9fa4_3e4e2e09b72d["FastAPI"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|defined in| 587454b3_6db6_011f_9fa4_3e4e2e09b72d bef02968_6cae_fc82_e854_8b053afd9655["__init__()"] bef02968_6cae_fc82_e854_8b053afd9655 -->|calls| c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d a9c07abb_aad1_48b4_2dbe_359121a449b2["openapi()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| a9c07abb_aad1_48b4_2dbe_359121a449b2 d15d0d82_652d_c556_d699_e3ccf1192b8e["get()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| d15d0d82_652d_c556_d699_e3ccf1192b8e 3705e434_dfc7_b070_aae6_93314a9b9976["get_swagger_ui_html()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| 3705e434_dfc7_b070_aae6_93314a9b9976 9e591d9c_65d6_09d8_497c_322cdf94b4b4["get_swagger_ui_oauth2_redirect_html()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| 9e591d9c_65d6_09d8_497c_322cdf94b4b4 609573dc_dd8d_bd61_f42b_83a7d4873d61["get_redoc_html()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| 609573dc_dd8d_bd61_f42b_83a7d4873d61 style c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/applications.py lines 1082–1133
def setup(self) -> None:
if self.openapi_url:
urls = (server_data.get("url") for server_data in self.servers)
server_urls = {url for url in urls if url}
async def openapi(req: Request) -> JSONResponse:
root_path = req.scope.get("root_path", "").rstrip("/")
if root_path not in server_urls:
if root_path and self.root_path_in_servers:
self.servers.insert(0, {"url": root_path})
server_urls.add(root_path)
return JSONResponse(self.openapi())
self.add_route(self.openapi_url, openapi, include_in_schema=False)
if self.openapi_url and self.docs_url:
async def swagger_ui_html(req: Request) -> HTMLResponse:
root_path = req.scope.get("root_path", "").rstrip("/")
openapi_url = root_path + self.openapi_url
oauth2_redirect_url = self.swagger_ui_oauth2_redirect_url
if oauth2_redirect_url:
oauth2_redirect_url = root_path + oauth2_redirect_url
return get_swagger_ui_html(
openapi_url=openapi_url,
title=f"{self.title} - Swagger UI",
oauth2_redirect_url=oauth2_redirect_url,
init_oauth=self.swagger_ui_init_oauth,
swagger_ui_parameters=self.swagger_ui_parameters,
)
self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False)
if self.swagger_ui_oauth2_redirect_url:
async def swagger_ui_redirect(req: Request) -> HTMLResponse:
return get_swagger_ui_oauth2_redirect_html()
self.add_route(
self.swagger_ui_oauth2_redirect_url,
swagger_ui_redirect,
include_in_schema=False,
)
if self.openapi_url and self.redoc_url:
async def redoc_html(req: Request) -> HTMLResponse:
root_path = req.scope.get("root_path", "").rstrip("/")
openapi_url = root_path + self.openapi_url
return get_redoc_html(
openapi_url=openapi_url, title=f"{self.title} - ReDoc"
)
self.add_route(self.redoc_url, redoc_html, include_in_schema=False)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does setup() do?
setup() is a function in the fastapi codebase, defined in fastapi/applications.py.
Where is setup() defined?
setup() is defined in fastapi/applications.py at line 1082.
What does setup() call?
setup() calls 5 function(s): get, get_redoc_html, get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html, openapi.
What calls setup()?
setup() is called by 1 function(s): __init__.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free