Skip to content

Options reference

The authoritative per-symbol API — signatures, doc comments — lives on pkg.go.dev; this page is the at-a-glance map.

Register

func Register(mux *http.ServeMux, spec []byte, opts ...Option) error

Mounts, on mux:

Route Handler
GET {specPath} writes spec with Content-Type: application/yaml
GET {docsPath}{$} the generated Stoplight index HTML
GET {docsPath} the embedded UI assets (JS/CSS), stripped of the docs prefix

Returns an error only if the embedded assets or the index template fail to load/render (both are build-time constants, so in practice this is nil).

Options

Option Default Effect
WithSpecPath(p string) /openapi.yaml path the spec is served at
WithDocsPath(p string) /docs/ path prefix for the UI — must end in /
WithTitle(t string) API documentation docs page <title>
WithSecurityHeaderOptions(opts ...transporthttp.SecurityHeadersOption) conservative defaults customise the security-header middleware
WithoutSecurityHeaders() (headers on) disable the built-in security-header wrapper

Defaults

Without options, Register(mux, spec) serves:

  • GET /openapi.yaml → the spec
  • GET /docs/ → the Stoplight UI, titled "API documentation"
  • both wrapped with go/transport's default security headers (nosniff, X-Frame-Options: DENY, frame-ancestors 'none', Referrer-Policy: no-referrer, HSTS off)

Dependencies

transport-openapi depends on go/transport (security-header middleware) and go/transit (the Middleware type). Keep it at a matching minor with your go/transport (v0.1.xv0.1.x).