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.
Code
hono-docs.js
class="tk-cm">// gen-docs.js const { generateOpenAPI31 } = require(class="tk-str">39;@hyperbridge/forge/server39;); const fs = require(class="tk-str">39;fs39;); const app = require(class="tk-str">39;./app39;); class="tk-cm">// your WebApp const spec = generateOpenAPI31(app, { title: class="tk-str">39;My API39;, version: require(class="tk-str">39;./package.json39;).version, description: class="tk-str">39;Auto-generated from WebApp routes39;, }); fs.writeFileSync(class="tk-str">39;openapi.json39;, JSON.stringify(spec, null, 2)); console.log(class="tk-str">39;✓ openapi.json39;);
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
This is HBForge's port of Hono's example. Read the original at hono.dev/examples/hono-docs.