openapi

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package openapi serves an OpenAPI specification and a Stoplight Elements docs site (interactive, with a "try it" console) from a single Register call. The Stoplight Elements assets are embedded in the framework, so a project ships only its generated spec — no per-project vendoring of the UI.

The Stoplight Elements distribution under assets/ is vendored from https://stoplight.io/open-source/elements (Apache-2.0), pinned at v9.0.0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

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

Register mounts the OpenAPI spec and the Stoplight Elements docs site onto the provided mux:

GET /openapi.yaml  -> the spec bytes
GET /docs/         -> the Stoplight UI (try-it console)

Serving both on the same server keeps the spec same-origin with the API it documents, so the "try it" console works without extra CORS configuration.

Types

type Option

type Option func(*config)

Option configures the docs endpoints.

func WithDocsPath

func WithDocsPath(p string) Option

WithDocsPath sets the path prefix the Stoplight UI is served at (default "/docs/"). It must end in a slash.

func WithSecurityHeaderOptions added in v0.17.0

func WithSecurityHeaderOptions(opts ...gtbhttp.SecurityHeadersOption) Option

WithSecurityHeaderOptions customises the security-header middleware applied to the docs/spec handlers. By default the conservative http.SecurityHeadersMiddleware defaults are used (nosniff, X-Frame-Options: DENY, frame-ancestors 'none', Referrer-Policy: no-referrer, HSTS off).

func WithSpecPath

func WithSpecPath(p string) Option

WithSpecPath sets the path the OpenAPI document is served at (default "/openapi.yaml").

func WithTitle

func WithTitle(t string) Option

WithTitle sets the docs page title.

func WithoutSecurityHeaders added in v0.17.0

func WithoutSecurityHeaders() Option

WithoutSecurityHeaders disables the default security-header middleware on the docs/spec handlers. Use this only when an outer middleware chain already sets equivalent headers; the built-in interactive docs UI is otherwise served without nosniff/frame/referrer protections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL