Skip to content

Validate every API response

Generate the Zod schemas, then point a client at them. Setting the Fetch client's validator to 'zod' runs every response body through the matching schema at runtime. To validate request bodies too, use the object form { request: 'zod', response: 'zod' }.

kubb.config.ts
typescript
import { 
defineConfig
} from 'kubb/config'
import {
pluginTs
} from '@kubb/plugin-ts'
import {
pluginZod
} from '@kubb/plugin-zod'
import {
pluginFetch
} from '@kubb/plugin-fetch'
export default
defineConfig
({
input
: './petStore.yaml',
output
: {
path
: './src/gen',
clean
: true },
plugins
: [
pluginTs
(),
pluginZod
(),
pluginFetch
({
validator
: 'zod',
}), ], })