Skip to main content
The Zod plugin generates Zod schemas from your OpenAPI specification. Zod is a TypeScript-first schema validation library with static type inference, zero dependencies, and excellent developer experience.

Installation

Install the required dependencies:

Configuration

Add the Zod plugin to your openapi-ts.config.ts:
openapi-ts.config.ts

Compatibility Versions

The Zod plugin supports multiple Zod versions through the compatibilityVersion option:
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:
Customize definition schema names and casing:
Generated output:
zod.gen.ts

Requests

Generate validators for API request data (body, query, path, headers):
Generated output:
zod.gen.ts

Responses

Generate validators for API responses:
Generated output:
zod.gen.ts

Webhooks

Generate validators for webhook payloads:

Type Inference

Generate TypeScript types from Zod schemas:
Configure type generation per schema category:
Generated output:
zod.gen.ts

Date Handling

Configure how date and datetime values are validated:
Generates: z.iso().datetime()Validates: 2024-01-15T12:30:00Z

Metadata Support

Enable Zod metadata for additional schema information:
Metadata is useful for documentation, code generation, AI structured outputs, and form validation.

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:

Validators Overview

Learn about validator plugins and their benefits

Valibot Plugin

Alternative validator with smaller bundle size

Zod Documentation

Official Zod library documentation