Skip to content
Plugin
Zod logo
plugins: [pluginZod()]
Officialv5.13.3kubb >=5.19.0node >=22.22

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.

kubb add plugin-zod
Repositorynpmx

Stijn Van Hulle

@stijnvanhulle

zodvalidationschemaruntime-validationcodegenopenapi
  • Downloads
    1.4M/ monthnpm, last 30 days
  • GitHub stars
    15kubb-labs/plugins
  • Unpacked size
    717.8kBv5.13.3 on npm
  • Latest release
    3d agov5.13.3 · Nov 26, 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-zod

kubb 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 zod v4 in the app that uses the generated code. Some options need a newer minor:
OptionNeeds
oneOfType: 'xor'Zod 4.2 or later
compileZod 4.5 or later
typeGuardsZod 4.6 or later

Options worth knowing

OptionDefaultWhat it does
inferredfalseAdds a z.infer type next to each schema, so you can skip @kubb/plugin-ts.
minifalseBeta. Generates Zod Mini schemas for smaller bundles.
coercionfalseCoerces input before validation, such as query strings.
oneOfType'union'Validates a oneOf with z.union or z.xor.
typeGuardsfalseAdds is* type guards and assert* assertions.
compilefalseWraps 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 })],
})

Next, customize the generated schemas.

Dependencies

No extension dependencies.

Used by

Extensions that list Zod as a dependency.

Axios logo
Axios
@kubb/plugin-axiosGenerates a type-safe axios client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
Client logo
Client
@kubb/plugin-clientGenerates typed operation functions from your OpenAPI spec that call a client module you own, so you decide the transport, auth, and error handling.
Fetch logo
Fetch
@kubb/plugin-fetchGenerates a type-safe Fetch API client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
Ky logo
Ky
@kubb/plugin-kyGenerates a type-safe Ky client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
MCP logo
MCP
@kubb/plugin-mcpGenerates a Model Context Protocol server from your OpenAPI spec, so AI assistants can call each operation as a typed tool.
React Query logo
React Query
@kubb/plugin-react-queryGenerates typed TanStack Query helpers for React from your OpenAPI spec: queryOptions and mutationOptions factories with cache keys, plus optional hooks.
SWR logo
SWR
@kubb/plugin-swrGenerates typed SWR hooks from your OpenAPI spec, so data fetching stays in sync with the API.
Vue Query logo
Vue Query
@kubb/plugin-vue-queryGenerates typed TanStack Query helpers for Vue from your OpenAPI spec: queryOptions factories with query and mutation keys, plus optional composables.