scalar

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

func WithUI

func WithUI(opts ...UIOption) stdocs.Option

WithUI returns a stdocs.Option that replaces the default docs page with the Scalar UI. Pass WithConfiguration to forward Scalar-native options; they override the CSP-safe defaults.

Types

type UIOption added in v0.7.0

type UIOption = uiopt.Option

UIOption configures the Scalar UI installed by WithUI.

func WithConfiguration added in v0.7.0

func WithConfiguration(cfg map[string]any) UIOption

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

Jump to

Keyboard shortcuts

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