zod-openapi is a TypeScript library that transforms Zod schemas into OpenAPI v3.x documentation. It leverages Zod's native `.meta()` method to embed OpenAPI-specific metadata directly into your schemas, allowing you to generate comprehensive API specifications effortlessly. The current stable version is `5.4.6`, and the package is actively maintained with frequent patch releases addressing compatibility and bug fixes, alongside regular minor updates for new features and improvements.
npm install zod-openapiVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define Zod schemas with OpenAPI metadata for request parameters, request bodies, and responses using `.meta()`. It then generates a complete OpenAPI 3.x document that includes definitions for creating and retrieving users.
Use the `zodSchemas` property within the `CreateDocumentOptions.override` function instead of directly on `.meta().override`.
If the previous rendering behavior for `z.undefined()` is required, use the `override` option in `.meta()` to customize the OpenAPI schema output.
Ensure you are on the latest `zod-openapi` version (`5.4.6` or newer) to address known compatibility issues with recent Zod v4.x releases.
Add `import 'zod-openapi';` or `import { createDocument } from 'zod-openapi';` (or any other named import) to a relevant TypeScript file, typically where `createDocument` is called.Update `zod-openapi` to version `5.4.3` or newer to resolve this specific TypeScript error.
Update `zod-openapi` to the latest patch version (e.g., `5.4.6` for Zod 4.3+ compatibility) to resolve known schema representation issues.
Ensure `zod-openapi` is imported in your project (e.g., `import { createDocument } from 'zod-openapi';`) to enable type augmentation.Update `zod-openapi` to version `5.4.4` or newer to fix issues related to discriminated union schema generation.
No dependency data recorded yet.