Scalar

Interactive API documentation with Scalar API Reference

By default, SchemaPlugin serves Scalar API Reference at GET /_schema/docs. Scalar reads your live OpenAPI document from /_schema/ and renders a modern, interactive UI (try requests, browse models, multiple themes).

No separate Express/Fastify adapter is required - Vercube uses @scalar/client-side-rendering to return a self-contained HTML page that loads Scalar from a CDN (pinned to one version and checked with a Subresource Integrity hash).

Default behavior

After app.addPlugin(SchemaPlugin):

EndpointDescription
/_schema/OpenAPI 3.0 JSON (SchemaRegistry.generateSchema())
/_schema/docsScalar HTML UI pointing at /_schema/

Open http://localhost:<port>/_schema/docs while your app is running.

Both endpoints are off when the application runs with production: true. See Exposure and access to serve them in production, move them or guard them with a token.

Configuration

Pass options as the second argument to addPlugin or via withPluginOptions:

import { createApp, withPluginOptions } from '@vercube/core';
import { SchemaPlugin } from '@vercube/schema';

const app = await createApp({
  setup: async (app) => {
    app.addPlugin(
      SchemaPlugin,
      {
        scalar: {
          pageTitle: 'Acme API',
          openApiUrl: '/_schema/',
          config: {
            theme: 'purple',
          },
        },
      },
    );
  },
});
vercube.config.ts
import { defineConfig, withPluginOptions } from '@vercube/core';
import { SchemaPlugin } from '@vercube/schema';

export default defineConfig({
  plugins: [
    withPluginOptions(SchemaPlugin, {
      scalar: { pageTitle: 'Acme API' },
    }),
  ],
});

SchemaPluginOptions

OptionTypeDefaultDescription
enabledbooleantrue, false in productionServe the OpenAPI document and the Scalar UI
pathstring'/_schema'Path of the OpenAPI document, the UI is served at <path>/docs
tokenstring-Access token required by both endpoints
scalarfalse | SchemaScalarOptionsenabledSet to false to disable the docs route

SchemaScalarOptions

OptionTypeDefaultDescription
openApiUrlstring'<path>/'URL Scalar fetches for the OpenAPI document
pageTitlestring'API Reference'HTML <title>
cdnstringpinned jsDelivr URLURL of the @scalar/api-reference standalone bundle
configPartial<HtmlRenderingConfiguration>-Extra Scalar settings (theme, layout, etc.)

config accepts the same options as Scalar’s API Reference configuration (for example theme, custom CSS, multiple sources).

Self-hosting the bundle

The page loads one script, pinned to a fixed @scalar/api-reference version with an integrity hash, and is sent with a Content-Security-Policy that allows only that script's origin (plus a per-request nonce for the inline setup). To avoid a public CDN entirely, serve dist/browser/standalone.js from the @scalar/api-reference package yourself and point cdn at it:

app.addPlugin(SchemaPlugin, {
  scalar: { cdn: '/assets/scalar-standalone.js' },
});

A custom cdn is not sent with an integrity hash, since its content is yours to vouch for.

Disable Scalar

Keep OpenAPI JSON, hide the UI:

app.addPlugin(SchemaPlugin, { scalar: false });

GET /_schema/docs then returns 404.

Custom OpenAPI URL

If you proxy the spec or mount the app under a prefix, point Scalar at the correct spec URL:

app.addPlugin(SchemaPlugin, {
  scalar: {
    openApiUrl: '/api/v1/_schema/',
  },
});

The path must match where the document is actually served. To move both endpoints, set path instead: openApiUrl follows it.

Behind reverse proxies

Use an absolute or root-relative openApiUrl that the browser can reach, not an internal hostname. For example:

scalar: {
  openApiUrl: 'https://api.example.com/_schema/',
}

Types

Exported from @vercube/schema:

import type { SchemaPluginOptions, SchemaScalarOptions } from '@vercube/schema';