08 · Docs / OpenAPI
Zod-style schemas → OpenAPI 3.1
HBForge's schema builder is Zod-compatible by API — generateOpenAPI31() walks the router and produces a full spec from it.
Code
zod-openapi.js
const { WebApp, ObjectSchema, StringSchema, NumberSchema, generateOpenAPI31, swaggerUI, } = require(class="tk-str">39;@hyperbridge/forge/server39;); const app = new WebApp(); const Post = new ObjectSchema({ id: new NumberSchema().int(), title: new StringSchema().min(1), }); app.get(class="tk-str">39;/posts/:id39;, (c) => c.json({ id: +c.req.param(class="tk-str">39;id39;), title: class="tk-str">39;hello39;, })); app.get(class="tk-str">39;/openapi.json39;, (c) => c.json( generateOpenAPI31(app, { title: class="tk-str">39;Posts API39;, version: class="tk-str">39;1.039;, }) )); app.get(class="tk-str">39;/docs39;, (c) => c.html( swaggerUI({ url: class="tk-str">39;/openapi.json39; }) )); app.listen(3000);
How it works
No decorators, no plugin chain — schemas attached to routes via metadata produce a spec automatically.
Output is OpenAPI 3.1 (the JSON Schema 2020-12 dialect), which is the format Scalar, ReDoc, and modern Swagger UI all consume.
Saves the spec to disk by piping the JSON to fs.writeFileSync — useful for git-tracked, diffable API contracts.
Try it
Quickstart
open http://localhost:3000/docs
Related modules
This is HBForge's port of Hono's example. Read the original at hono.dev/examples/zod-openapi.