hono-zod-openapi is a middleware library for the Hono web framework that generates OpenAPI documentation directly from Zod schemas, offering a type-safe approach to API definition. Unlike some alternative solutions, it integrates as a standard Hono middleware, avoiding the need for significant refactoring of existing Hono applications. The current stable version is 1.1.1, released in February 2026. The project maintains an active release cadence, with frequent minor updates and bug fixes. Its key differentiator is the non-intrusive middleware pattern for OpenAPI definition, making it easy to adopt in existing Hono projects, along with providing a `createOpenApiDocument` function to serve the generated documentation.
npm install hono-zod-openapiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Hono route using the `openApi` middleware, link Zod schemas for request parameters and responses, and then generate and serve the OpenAPI document and Swagger UI.
Upgrade your Node.js environment to version 20 or newer to ensure compatibility and leverage the latest features and security updates.
Update your `zod` package to version `^4.0.0` or higher in your `package.json` and reinstall dependencies.
Upgrade to `hono-zod-openapi@1.0.3` or later. If upgrading is not possible, define all your OpenAPI-enabled routes before attaching generic `.onError` handlers.
Upgrade `hono-zod-openapi` to version `1.0.2` or later to ensure type compatibility with newer Hono versions.
Install Zod: `npm install zod@^4.0.0` or `yarn add zod@^4.0.0`. Ensure it meets the required version for hono-zod-openapi.
You need to explicitly use Hono's `validator` middleware (e.g., `import { validator } from '@hono/zod-validator';`) on your routes to enable request validation and access `c.req.valid()`.Ensure you are using `c.req.valid('param')` etc. within a Hono handler that has the `validator` middleware applied and that your project is configured for TypeScript with `hono` and `hono-zod-openapi` types correctly installed.