Scalar
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):
| Endpoint | Description |
|---|---|
/_schema/ | OpenAPI 3.0 JSON (SchemaRegistry.generateSchema()) |
/_schema/docs | Scalar 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',
},
},
},
);
},
});
import { defineConfig, withPluginOptions } from '@vercube/core';
import { SchemaPlugin } from '@vercube/schema';
export default defineConfig({
plugins: [
withPluginOptions(SchemaPlugin, {
scalar: { pageTitle: 'Acme API' },
}),
],
});
SchemaPluginOptions
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true, false in production | Serve the OpenAPI document and the Scalar UI |
path | string | '/_schema' | Path of the OpenAPI document, the UI is served at <path>/docs |
token | string | - | Access token required by both endpoints |
scalar | false | SchemaScalarOptions | enabled | Set to false to disable the docs route |
SchemaScalarOptions
| Option | Type | Default | Description |
|---|---|---|---|
openApiUrl | string | '<path>/' | URL Scalar fetches for the OpenAPI document |
pageTitle | string | 'API Reference' | HTML <title> |
cdn | string | pinned jsDelivr URL | URL of the @scalar/api-reference standalone bundle |
config | Partial<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';