Documentation
¶
Overview ¶
Package scalar provides a Scalar UI for stdocs.
Scalar is a modern OpenAPI viewer loaded from a CDN. To use it, import this sub-package and pass scalar.WithUI() to stdocs.New or stdocs.DocsHandler:
import (
"github.com/FumingPower3925/stdocs"
"github.com/FumingPower3925/stdocs/ui/scalar"
)
mux := stdocs.New(stdocs.WithTitle("My API"), scalar.WithUI())
mux.HandleFunc("GET /x", h)
mux.Mount() // or mount mux.Docs() on a parent mux
This sub-package adds the Scalar HTML to the docs handler. The Scalar JavaScript and CSS are loaded from cdn.jsdelivr.net at page load time, so an internet connection is required.
The CDN URL is pinned to a specific version (1.60.0) and points at the verbatim dist/browser/standalone.js file from the npm package, so its bytes are deterministic and the sha384 SRI hash below is pinned in the <script> tag. Bumping the pinned version requires re-computing the hash. For an air-gapped build, use the ui/scalaremb sub-package instead — it vendors the bundle in-repo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type UIOption ¶ added in v0.7.0
UIOption configures the Scalar UI installed by WithUI.
func WithConfiguration ¶ added in v0.7.0
WithConfiguration passes Scalar configuration to the docs page. The map is serialized to JSON and placed in Scalar's data-configuration attribute, so its keys are Scalar's configuration options — for example "theme", "layout", "hideModels", "hideSearch", or "documentDownloadType". The spec source is set by stdocs via data-url; keys that also point at a spec are the caller's responsibility. Keys override the CSP-safe defaults (see defaultConfig) at the TOP LEVEL only: a nested object such as "agent" replaces the default wholesale, so re-state any sub-key you want to keep. See the Scalar configuration reference: https://github.com/scalar/scalar/blob/main/documentation/configuration.md