Tree-shakeable schemas with Zod Mini
Set mini to true to generate Zod Mini schemas that use the functional API, so bundlers tree-shake the validators you never call. This also defaults the import to 'zod/mini'.
typescript
import { defineConfig } from 'kubb/config'
import { pluginZod } from '@kubb/plugin-zod'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', clean: true },
plugins: [
pluginZod({
mini: true,
}),
],
})Output example
typescript
import * as z from 'zod/mini'
import { categorySchema } from './categorySchema'
import { tagSchema } from './tagSchema'
export const petSchema = z.object({
id: z.optional(z.bigint()),
name: z.string(),
get category() { return z.optional(categorySchema) },
photoUrls: z.array(z.string()),
tags: z.optional(z.array(tagSchema)),
status: z.optional(z.enum(['available', 'pending', 'sold'])),
})typescript
import { petSchema } from './src/gen/zod/petSchema'
// only the validators actually imported end up in the bundle
const pet = petSchema.parse({ name: 'Rex', photoUrls: [] })