Documentation
¶
Overview ¶
Package stoplightemb provides an embedded (air-gapped) Stoplight Elements UI for stdocs.
Unlike the sibling ui/stoplight package, which loads Stoplight from a CDN at page-load time, ui/stoplightemb vendors the Stoplight web-component bundle in your binary so the docs UI works without an internet connection.
The vendored bundle is pinned to @stoplight/elements@9.0.22.
To use it:
import (
"net/http"
"github.com/FumingPower3925/stdocs"
"github.com/FumingPower3925/stdocs/ui/stoplightemb"
)
mux := stdocs.New(stdocs.WithTitle("My API"), stoplightemb.WithUI())
mux.HandleFunc("GET /x", h)
mux.Mount() // registers the docs AND the embedded asset route
Mount registers the asset route automatically (and tolerates a pre-existing manual registration). Only a manually mounted docs handler needs its own asset registration:
mux.ServeMux.Handle("GET /docs/", mux.Docs())
mux.ServeMux.Handle("GET /docs/_assets/", http.StripPrefix(
"/docs/_assets/", stoplightemb.AssetHandler()))
The asset handler adds about 2.4 MB to your binary and is only included if you import this sub-package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetHandler ¶
AssetHandler returns an http.Handler that serves the embedded Stoplight web components at the root. File responses carry an immutable Cache-Control header; directory requests return 404. Mount it on your mux with a path strip, e.g.:
mux.Handle("GET /docs/_assets/", http.StripPrefix("/docs/_assets/", stoplightemb.AssetHandler()))
Types ¶
type UIOption ¶ added in v0.7.0
UIOption configures the embedded Stoplight Elements UI installed by WithUI.
func WithConfiguration ¶ added in v0.7.0
WithConfiguration passes Stoplight Elements configuration to the docs page. Stoplight Elements has no JSON configuration object — it is configured through attributes on its <elements-api> element — so the map's keys are rendered as element attributes and its values must be strings, booleans, or numbers. Keys are Stoplight attribute names, for example "hideTryItPanel", "hideSchemas", "tryItCredentialsPolicy", or "logo". apiDescriptionUrl, router, and layout are set by stdocs and cannot be overridden. See the Stoplight Elements configuration reference: https://github.com/stoplightio/elements/blob/main/docs/getting-started/elements/elements-options.md