Installation
Install the required dependencies:Configuration
Add the Zod plugin to youropenapi-ts.config.ts:
openapi-ts.config.ts
Compatibility Versions
The Zod plugin supports multiple Zod versions through thecompatibilityVersion option:
- Zod 4 (Default)
- Zod 3
- Zod Mini
Generates schemas compatible with Zod 4:The plugin auto-detects your installed Zod version and uses version 4 by default if Zod 4.x is installed.
The plugin automatically detects your installed Zod version and warns you if there’s a mismatch with your configured
compatibilityVersion.Schema Generation
Definitions
Generate schemas for reusable component definitions:zod.gen.ts
Requests
Generate validators for API request data (body, query, path, headers):zod.gen.ts
Responses
Generate validators for API responses:zod.gen.ts
Webhooks
Generate validators for webhook payloads:Type Inference
Generate TypeScript types from Zod schemas:zod.gen.ts
Date Handling
Configure how date and datetime values are validated:- Default (ISO with timezone)
- With Offset
- Local (No Timezone)
z.iso().datetime()Validates: 2024-01-15T12:30:00ZMetadata Support
Enable Zod metadata for additional schema information:Usage Examples
Validating API Requests
Validating API Responses
Type Inference
Form Validation with React Hook Form
Advanced Configuration
Custom Naming Patterns
Use functions for dynamic naming:Selective Schema Generation
Disable specific schema categories:Global Configuration
Type Reference
The Zod plugin exports these configuration types:Related
Validators Overview
Learn about validator plugins and their benefits
Valibot Plugin
Alternative validator with smaller bundle size
Zod Documentation
Official Zod library documentation