Skip to content

Customise the spec and docs paths

By default Register serves the spec at /openapi.yaml and the docs UI at /docs/, titled "API documentation". Override any of these with options.

Version the routes under a prefix

openapi.Register(mux, spec,
    openapi.WithSpecPath("/v1/openapi.yaml"),
    openapi.WithDocsPath("/v1/docs/"),
    openapi.WithTitle("Acme API v1"),
)
Route Serves
GET /v1/openapi.yaml the spec
GET /v1/docs/ the Stoplight UI

The docs page points at whatever WithSpecPath resolves to, so the two stay in sync automatically — you only set the paths, the UI is wired to them.

Rules

  • WithDocsPath must end in a slash (/docs/, not /docs). The exact path serves the generated index; the subtree serves the embedded JS/CSS.
  • Mount more than one. Registering different WithSpecPath / WithDocsPath pairs on the same mux lets a server expose several API versions side by side — each call is independent.

Title

openapi.Register(mux, spec, openapi.WithTitle("Payments API"))

The title appears in the browser tab of the docs page. It does not affect the spec.