Hono
Install
npm install @hono/zod-openapi zod
Setup
Use OpenAPIHono instead of the base Hono class and define routes with Zod schemas:
// app.ts
import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi'
const app = new OpenAPIHono()
const GetItemRoute = createRoute({
method: 'get',
path: '/items/{id}',
operationId: 'getItem',
summary: 'Get a single item',
request: {
params: z.object({
id: z.string().openapi({ example: '1' }),
}),
},
responses: {
200: {
content: {
'application/json': {
schema: z.object({ id: z.string(), name: z.string() }),
},
},
description: 'Item found',
},
},
})
app.openapi(GetItemRoute, (c) => {
const { id } = c.req.valid('param')
return c.json({ id, name: 'Widget' })
})
// Expose the spec
app.doc('/openapi.json', {
openapi: '3.0.0',
info: { title: 'My API', version: '1.0.0' },
})
export default app
The spec is available at:
http://localhost:3000/openapi.json
Make it publicly accessible
Deploy your app (Cloudflare Workers, Vercel, etc.) or use a tunnel for local testing:
ngrok http 3000
# then use: https://<random>.ngrok.io/openapi.json
Verify
Visit /openapi.json in your browser. You should see a valid OpenAPI 3.x JSON document.
Paste this URL into Automiel’s import step.