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:
| route | renderer | FastAPI analogue |
|---|---|---|
/docs | Swagger UI | /docs |
/redoc | ReDoc | /redoc |
/scalar | Scalar | — (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, andblob: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
/docspage HTML. Historically this served Scalar; it now serves Swagger UI for FastAPI parity. Kept so downstreampub usesites 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— servesSWAGGER_HTMLunder the scopedDOCS_CSP.- redoc_
handler GET /redoc— servesREDOC_HTMLunder the scopedDOCS_CSP.- scalar_
handler GET /scalar— servesSCALAR_HTMLunder the scopedDOCS_CSP.