Write Your Routes
Write your Hono routes like normal, using @hono/zod-validator. To strongly type your API responses, wrap your JSON responses in the typed() helper from @mmtq/hono-swagger/helpers. You can also use standard JSDoc comments to enrich your documentation!
typescript
import { Hono } from 'hono';
import { z } from 'zod';
import { zValidator } from '@hono/zod-validator';
import { typed } from '@mmtq/hono-swagger/helpers';
const app = new Hono();
export const UserSchema = z.object({
id: z.string().uuid(),
name: z.string(),
age: z.number().int().min(0)
});
/**
* @summary Get a user by ID
* @description Fetches a user securely from the database.
* @tags Users
*/
app.get('/users/:id', zValidator('param', z.object({ id: z.string() })), (c) => {
const { id } = c.req.valid('param');
// typed() ensures your response matches UserSchema!
return typed(c, UserSchema, { id, name: 'Alice', age: 30 });
});Supported JSDoc Tags
| Tag | Description |
|---|---|
@summary <text> | Short one-line summary of the route. |
@description <text> | Longer description shown in the docs. |
@tags <comma, separated, tags> | Group routes under tags. |
@deprecated | Marks the route as deprecated. |
@openapi-ignore | Hides the route from the generated documentation. |