transport-openapi¶
Serve an OpenAPI spec and an interactive Stoplight Elements docs site from one
Register call.
Hand Register your *http.ServeMux and your OpenAPI document, and your server
gains a live API reference — with a "try it" console — at /docs/, plus the raw
spec at /openapi.yaml. The Stoplight Elements UI is embedded in the module, so a
project ships only its generated spec.
mux := http.NewServeMux()
// mount your API handlers…
if err := openapi.Register(mux, specYAML); err != nil {
return err
}
Highlights¶
- One call.
Register(mux, spec, opts...)mounts both the spec and the docs UI. - Same-origin. Spec and docs are served from the same server as the API, so the try-it console needs no CORS setup.
- Secure by default. Docs/spec handlers are wrapped with
go/transport's conservative security-header middleware; customise or opt out. - Opt-in weight. A companion to
go/transport— the ~2.4 MB embedded UI never bloats a server that doesn't serve docs.
Where next¶
- Getting started — a runnable server with API docs.
- How-to — customise paths & title, security headers, serve on a go/transport server.
- Reference — options, and the API on pkg.go.dev.
- Explanation — why a companion module, same-origin docs by design.
Part of the phpboyscout Go toolkit — a companion to go/transport.