Plugin
plugins: [pluginZod()]Officialv5.4.8kubb >=5.8.3node >=22
Zod
@kubb/plugin-zod
Generates Zod v4 schemas from your OpenAPI spec so you validate API responses, form input, and query params at runtime.
kubb add plugin-zod
zodvalidationschemaruntime-validationcodegenopenapi
- Downloads923.8K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size586.3kBv5.4.8 on npm
- Latest release9h agov5.4.8 · Oct 13, 2026
The Zod plugin generates a Zod v4 schema for every schema in your OpenAPI spec.
The client plugins @kubb/plugin-fetch, @kubb/plugin-axios, and @kubb/plugin-client use these schemas when you set their validator option.
Installation
bun add -d @kubb/plugin-zodpnpm add -D @kubb/plugin-zodnpm install --save-dev @kubb/plugin-zodyarn add -D @kubb/plugin-zodOr run kubb add plugin-zod to install the version the Kubb registry pins and add pluginZod() to kubb.config.ts.
Setup
- No other plugins are needed.
- Install
zodv4 in the app that uses the generated code.compileneeds 4.5 or later, andtypeGuardsneeds 4.6 or later.
Options worth knowing
mini(beta) generates Zod Mini schemas for smaller bundles, and switchesimportPathtozod/mini.importPathsets the module the generated files importzfrom. The default iszod.inferredadds az.infertype next to each schema, so you can skip@kubb/plugin-ts.coercionwraps schemas inz.coerce, so input is converted before validation. Pass an object to coerce only dates, strings, or numbers.guidTypepicksz.uuid()(default) orz.guid()forformat: uuid.regexTypewrites apatternas a regex literal (default) or aRegExpconstructor.typeGuardsaddsis*type guards andassert*assertions.compilewraps schemas inz.compilefor faster validation. Circular schemas are left as they are.
See Options for every option and its default.
Example
The config below generates the schemas with a z.infer type next to each one.
kubb.config.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 }),
],
})Dependencies
No extension dependencies.
Used by
Extensions that list Zod as a dependency.