HBForge/Examples
12 · Docs / OpenAPI

Static docs as a CI step

Bake the OpenAPI spec to disk during build. Plug into a docs deploy pipeline for git-tracked, diffable API contracts.

forge/serverNode (build)
Code
hono-docs.js
class="tk-cm">// gen-docs.js
const { generateOpenAPI31 } = require(class="tk-str">'@hyperbridge/forge/server');
const fs  = require(class="tk-str">'fs');
const app = require(class="tk-str">'./app');   class="tk-cm">// your WebApp

const spec = generateOpenAPI31(app, {
  title:       class="tk-str">'My API',
  version:     require(class="tk-str">'./package.json').version,
  description: class="tk-str">'Auto-generated from WebApp routes',
});

fs.writeFileSync(class="tk-str">'openapi.json', JSON.stringify(spec, null, 2));
console.log(class="tk-str">'✓ openapi.json');
How it works

Run this as part of npm run build or as a pre-commit hook. The resulting openapi.json goes in git so spec changes are visible in code review.

Combine with oasdiff or openapi-diff to catch breaking changes in CI.

Publish the spec to a static host (Vercel, Netlify, S3) and point Scalar/ReDoc at the URL — zero runtime cost.

Try it
Quickstart
node gen-docs.js && git diff openapi.json
Related modules