@kubb/plugin-zod
@kubb/plugin-zod turns your OpenAPI schemas into Zod v4 schemas. Use them to validate API responses at runtime, build form schemas, or feed router libraries that take Zod (tRPC, Hono, Elysia).
Pair it with a client plugin (@kubb/plugin-axios or @kubb/plugin-fetch) and set the client's validator: 'zod' to validate every response.
Installation
shell
bun add -d @kubb/plugin-zod@betashell
pnpm add -D @kubb/plugin-zod@betashell
npm install --save-dev @kubb/plugin-zod@betashell
yarn add -D @kubb/plugin-zod@betaDependencies
The generated schemas stand alone: they import z from your project, so add Zod v4 to your dependencies. Set inferred: true to export a z.infer type alias next to each schema, which makes the schemas the single source of truth for types without @kubb/plugin-ts.
Example
typescript
import { } from 'kubb'
import { } from '@kubb/plugin-zod'
export default ({
: { : './petStore.yaml' },
: { : './src/gen' },
: [
({
: { : './zod' },
: { : 'tag', : ({ }) => `${}Schemas` },
: true,
: 'zod',
}),
],
})