Skip to main content

Embedded Assets

By default, UI CSS and JavaScript are loaded from CDN. This keeps your binary small and requires no extra setup. For offline or air-gapped environments, use the embedded (*emb) packages instead.

CDN Mode (Default)

Import a standard provider package — assets are loaded from CDN at runtime:

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

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

r.Get(handler.DocsPath(), handler.DocsFunc())
r.Get(handler.SpecPath(), handler.SpecFunc())
// No assets route needed in CDN mode

Embedded Mode

Import the *emb package variant — assets are bundled into the binary:

import (
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec-ui/swaggeruiemb" // embedded variant
)

handler := specui.NewHandler(
specui.WithSpecFile("openapi.yaml"),
swaggeruiemb.WithUI(), // embeds assets into binary
)

r.Get(handler.DocsPath(), handler.DocsFunc())
r.Get(handler.SpecPath(), handler.SpecFunc())

// Register the assets route when in embedded mode
if handler.AssetsEnabled() {
r.Get(handler.AssetsPath()+"/*", handler.Assets().ServeHTTP)
}

handler.AssetsEnabled() returns true only when using an *emb package.

Provider Package Reference

ProviderCDNEmbedded
Swagger UIgithub.com/oaswrap/spec-ui/swaggeruigithub.com/oaswrap/spec-ui/swaggeruiemb
Stoplight Elementsgithub.com/oaswrap/spec-ui/stoplightgithub.com/oaswrap/spec-ui/stoplightemb
ReDocgithub.com/oaswrap/spec-ui/redocgithub.com/oaswrap/spec-ui/redocemb
Scalargithub.com/oaswrap/spec-ui/scalargithub.com/oaswrap/spec-ui/scalaremb
RapiDocgithub.com/oaswrap/spec-ui/rapidocgithub.com/oaswrap/spec-ui/rapidocemb

Customizing the Assets Path

The default assets URL prefix is /docs/_assets. Override it:

handler := specui.NewHandler(
specui.WithAssetsPath("/static/api-ui"),
swaggeruiemb.WithUI(),
)

Benefits of Embedded Mode

  • No CDN dependency — works in air-gapped or restricted network environments
  • Deterministic builds — UI version is pinned at build time
  • Single binary — deploy without any external files

Benefits of CDN Mode

  • Smaller binary — UI assets are not included in the binary
  • Always up-to-date — CDN serves the pinned version configured in the library
  • Faster builds — no large asset files to compile