plugins: [pluginZod()]OpenAPI to Zod schema generator
@kubb/plugin-zod
Generates Zod v4 schemas from your OpenAPI spec so you validate API responses, form input, and query params at runtime.
- Downloads1.3M/ monthnpm, last 30 days
- GitHub stars14kubb-labs/plugins
- Unpacked size695.4kBv5.10.0 on npm
- Latest release4h agov5.10.0 · Nov 23, 2026
The Zod plugin generates a Zod v4 schema for every schema in your OpenAPI spec, plus the parameter, request, and response schemas of each operation.
@kubb/plugin-fetch, @kubb/plugin-axios, and @kubb/plugin-client validate with these schemas when you set their validator option.
Installation
kubb add plugin-zodbun add -d @kubb/plugin-zodpnpm add -D @kubb/plugin-zodnpm install --save-dev @kubb/plugin-zodyarn add -D @kubb/plugin-zodkubb add installs the version the Kubb registry pins and adds pluginZod() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
- No other plugins are needed.
- Install
zodv4 in the app that uses the generated code. Some options need a newer minor:
| Option | Needs |
|---|---|
oneOfType: 'xor' | Zod 4.2 or later |
compile | Zod 4.5 or later |
typeGuards | Zod 4.6 or later |
Options worth knowing
| Option | Default | What it does |
|---|---|---|
inferred | false | Adds a z.infer type next to each schema, so you can skip @kubb/plugin-ts. |
mini | false | Beta. Generates Zod Mini schemas for smaller bundles. |
coercion | false | Coerces input before validation, such as query strings. |
oneOfType | 'union' | Validates a oneOf with z.union or z.xor. |
typeGuards | false | Adds is* type guards and assert* assertions. |
compile | false | Wraps schemas in z.compile for faster validation. |
Example
This config generates the schemas with a z.infer type next to each one. For a Pet schema, the plugin writes petSchema.ts:
import { defineConfig } from 'kubb/config'
import { pluginZod } from '@kubb/plugin-zod'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [pluginZod({ inferred: true })],
})import * as z from 'zod'
export const petSchema = z.object({
id: z.int(),
name: z.string(),
status: z.string().optional(),
tags: z.array(z.string()).optional(),
})
export type PetSchemaType = z.infer<typeof petSchema>Dependencies
No extension dependencies.
Used by
Extensions that list Zod as a dependency.
