@theokit/plugin-openapi
v0.1.3
Published
OpenAPI docs UI for TheoKit — mounts Scalar at /api/docs reading the .theo/openapi.json emitted by theokit build/dev.
Maintainers
Readme
@theokit/plugin-openapi
OpenAPI docs UI for TheoKit. Mounts Scalar at
/api/docsreading the.theo/openapi.jsonemitted bytheokit build(ortheokit devafter P#3 ships).
Zero npm runtime deps on @scalar/* — the UI loads from https://cdn.jsdelivr.net/npm/@scalar/api-reference at request time in the browser. Consumer-app bundle delta: 0 bytes.
Install
pnpm add @theokit/plugin-openapiRequires theokit >= 0.2.2 (peerDep). Earlier theokit versions don't emit .theo/openapi.json automatically in dev mode.
Quickstart
In your theo.config.ts:
import { defineConfig } from 'theokit'
import openApiPlugin from '@theokit/plugin-openapi'
export default defineConfig({
// Opt into G2's OpenAPI emit
openapi: {
title: 'My App',
version: '1.0.0',
servers: [{ url: 'http://localhost:3000' }],
},
// Mount the UI
plugins: [openApiPlugin()],
})Then pnpm dev and open http://localhost:3000/api/docs.
Options
openApiPlugin({
docsPath: '/api/docs', // HTML page path
openapiJsonPath: '/api/docs/openapi.json', // JSON served from disk
openapiSourcePath: '.theo/openapi.json', // on-disk emit location
cdnUrl: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference',
pageTitle: 'API Reference',
})Offline mode
The default loads Scalar from jsdelivr CDN. For air-gapped deployments, host the Scalar bundle yourself and override cdnUrl:
openApiPlugin({
cdnUrl: '/static/scalar/api-reference.js',
})See Scalar's CDN docs for the standalone bundle layout.
How it works
theokit dev/theokit buildemits.theo/openapi.json(ordist/openapi.jsonfor prod) whenconfig.openapiis defined (G2 feature, P#3 dev hook).GET /api/docs→ plugin serves HTML referencing Scalar's CDN script.GET /api/docs/openapi.json→ plugin reads the on-disk file + serves asapplication/json(or503 OPENAPI_NOT_EMITTEDif absent).
License
MIT
