Skip to content

Validate requests and responses

Set validator to { request: 'zod', response: 'zod' } so the client checks both request and response bodies against the generated schemas at runtime, and add @kubb/plugin-zod to the plugins list. The 'zod' shorthand covers responses only, so name both directions to validate requests too.

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
: {
request
: 'zod',
response
: 'zod' },
}), ], })