Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content
Official v5.0.0-beta.79 MIT kubb >=5.0.0 node >=22

@kubb/plugin-zod

Generate Zod v4 schemas from OpenAPI for runtime validation that stays in sync with your TypeScript types.

zodvalidationschemaruntime-validationcodegenopenapi
Downloads
545k / mo
Stars
3
Bundle size
412.6 kB
Updated
today

@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@beta
shell
pnpm add -D @kubb/plugin-zod@beta
shell
npm install --save-dev @kubb/plugin-zod@beta
shell
yarn add -D @kubb/plugin-zod@beta

Dependencies

@kubb/plugin-zod pairs with @kubb/plugin-ts. Add pluginTs to the plugins list when typed: true, since the generated schemas reference the TypeScript types it produces. Without typed, the schemas stand alone, and inferred: true exports their z.infer types so you do not need pluginTs at all.

Example

typescript
import {  } from 'kubb'
import {  } from '@kubb/plugin-ts'
import {  } from '@kubb/plugin-zod'

export default ({
  : { : './petStore.yaml' },
  : { : './src/gen' },
  : [
    (),
    ({
      : { : './zod' },
      : { : 'tag', : ({  }) => `${}Schemas` },
      : true,
      : 'zod',
    }),
  ],
})

See Also