Skip to main content

Module docs

Module docs 

Source
Expand description

The interactive API-reference pages — Seiva’s FastAPI /docs parity.

FastAPI serves Swagger UI at /docs and ReDoc at /redoc out of the box, both rendering the service’s own OpenAPI document. Seiva matches that and adds a third, modern renderer:

routerendererFastAPI analogue
/docsSwagger UI/docs
/redocReDoc/redoc
/scalarScalar— (bonus)

Every page points at the relative /openapi.json, so it works behind any host or path prefix, and the document itself is generated from the facades linked into the binary (no hand-written spec, no per-handler annotations — the async fn contract is the source). The viewer bundles load from a CDN, as FastAPI’s Swagger/ReDoc assets do; these are developer-facing documentation pages, not data-plane responses, so the CDN dependency is acceptable here.

Because the framework’s default response CSP is default-src 'none' (see security_headers), these pages would otherwise load nothing — the CDN script and the inline bootstrap would both be blocked and the page would render blank. So each handler sets its own, narrower CSP (DOCS_CSP) that permits exactly the CDN and the same-origin spec fetch; security_headers only fills in a header that is absent, so this scoped policy wins for the docs pages while every API/JSON response keeps the strict default.

Constants§

DOCS_CSP
The Content-Security-Policy for the documentation pages — narrower than a wildcard, wider than the API’s default-src 'none'. It permits only what the viewers need: their scripts and styles from jsDelivr (plus the inline bootstrap), data/CDN images and fonts, a same-origin fetch of /openapi.json, and blob: web workers (ReDoc renders in a worker). Everything else stays denied, so the documentation pages are no softer than they must be.
DOCS_HTML
Back-compat alias: the /docs page HTML. Historically this served Scalar; it now serves Swagger UI for FastAPI parity. Kept so downstream pub use sites keep compiling.
REDOC_HTML
GET /redoc — ReDoc over the service’s /openapi.json. FastAPI’s second built-in renderer; a three-pane reference that reads well for large APIs.
SCALAR_HTML
GET /scalar — Scalar, a single-page modern API reference. Kept as a bonus renderer alongside the FastAPI-parity Swagger UI and ReDoc pages.
SWAGGER_HTML
GET /docs — Swagger UI over the service’s /openapi.json. This is the FastAPI-identical route and renderer: the same page a FastAPI developer reaches at /docs, so the muscle memory transfers.

Functions§

docs_handler
GET /docs — serves SWAGGER_HTML under the scoped DOCS_CSP.
redoc_handler
GET /redoc — serves REDOC_HTML under the scoped DOCS_CSP.
scalar_handler
GET /scalar — serves SCALAR_HTML under the scoped DOCS_CSP.