Factory.ai

Open-Source Wikis

/

FastAPI

/

API

/

Auto-served routes

fastapi/fastapi

Auto-served routes

The FastAPI constructor registers a small set of routes for documentation and schema serving. Each can be disabled or relocated.

Default path Default method Constructor parameter Source Purpose
/openapi.json GET openapi_url fastapi/applications.py Serves the OpenAPI document produced by app.openapi(). Set to None to hide.
/docs GET docs_url fastapi/openapi/docs.py:get_swagger_ui_html Swagger UI page that loads openapi_url. Set to None to hide.
/docs/oauth2-redirect GET swagger_ui_oauth2_redirect_url fastapi/openapi/docs.py:get_swagger_ui_oauth2_redirect_html Tiny page that bridges OAuth2 authorization-code flow back to Swagger UI. Set to None to disable; OAuth2 still works for password/client-credentials flows.
/redoc GET redoc_url fastapi/openapi/docs.py:get_redoc_html ReDoc page that loads openapi_url. Set to None to hide.

All four endpoints have include_in_schema=False, so they do not appear in the OpenAPI document themselves.

Customising the docs UIs

FastAPI.__init__ accepts knobs for each:

  • swagger_ui_init_oauth: dict — passed to Swagger UI's initOAuth(...) call. Useful for prefilling clientId, appName, etc.
  • swagger_ui_parameters: dict — extra UI configuration, merged onto swagger_ui_default_parameters from fastapi/openapi/docs.py.
  • swagger_js_url, swagger_css_url, swagger_favicon_url — override the CDN URLs.
  • redoc_js_url, redoc_favicon_url — same for ReDoc.

For air-gapped environments, host the JS/CSS yourself and point the URLs at your static server.

Implementation

The constructor calls setup() which adds the routes when the corresponding *_url parameters are non-None. Each route is a path-operation function that returns an HTMLResponse (for /docs and /redoc) or a JSONResponse (for /openapi.json) built from app.openapi().

The OpenAPI dict is cached on app.openapi_schema. Mutating it after first generation is supported and survives across requests until you set app.openapi_schema = None or restart the app.

Mounted-app caveat

When a FastAPI instance is mounted at a sub-path (for example app.mount("/api", sub_app)), the auto-served routes use paths relative to the mount. Swagger UI inside sub_app will load /api/openapi.json. The OpenAPI generator handles root_path correctly through Starlette's request scope.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Auto-served routes – FastAPI wiki | Factory