Skip to main content

Scalar

Scalar is a feature-rich modern API documentation interface with built-in themes, search, and code generation. It's an excellent choice for public-facing APIs.

Installation

go get github.com/oaswrap/spec-ui/scalar

Usage

import (
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec-ui/scalar"
)

handler := specui.NewHandler(
specui.WithTitle("My API"),
specui.WithSpecFile("openapi.yaml"),
scalar.WithUI(),
)

With Configuration

import (
"github.com/oaswrap/spec-ui/config"
"github.com/oaswrap/spec-ui/scalar"
)

handler := specui.NewHandler(
specui.WithTitle("My API"),
specui.WithSpecFile("openapi.yaml"),
scalar.WithUI(config.Scalar{
DarkMode: true,
Layout: "modern",
Theme: "moon",
DocumentDownloadType: "both",
}),
)

Configuration Reference

FieldTypeDefaultDescription
ProxyURLstring""Proxy URL for API requests
HideSidebarboolfalseHide sidebar navigation
HideModelsboolfalseHide models in the sidebar
DocumentDownloadTypestring"both"Download type: "json", "yaml", "both", or "none"
HideTestRequestButtonboolfalseHide the "Test Request" button
HideDeveloperToolsboolfalseHide developer tools
HideSearchboolfalseHide the search bar
DarkModeboolfalseEnable dark mode
Layoutstring"modern"Layout: "modern" or "classic"
Themestring"default"Theme name (see Scalar themes)

Embedded Mode

Use scalaremb for air-gapped deployments:

import "github.com/oaswrap/spec-ui/scalaremb"

handler := specui.NewHandler(
specui.WithSpecFile("openapi.yaml"),
scalaremb.WithUI(),
)

if handler.AssetsEnabled() {
r.Get(handler.AssetsPath()+"/*", handler.Assets().ServeHTTP)
}