---
url: /plugins/plugin-zod/recipes/zod-as-the-single-source-of-truth.md
description: >-
  Export a z.infer alias next to every schema so Zod carries the types and you
  drop plugin-ts.
---

# Zod as the single source of truth

Turn on [`inferred`](/plugins/plugin-zod/reference/options#inferred) to export a `z.infer` alias next to every schema. The schemas then carry the types too, so you drop `@kubb/plugin-ts` from the config.

```typescript [kubb.config.ts]
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({
      output: { path: 'zod', mode: 'directory' },
      inferred: true,
    }),
  ],
})
```

## Output example

```typescript [src/gen/zod/categorySchema.ts]
import * as z from 'zod'

export const categorySchema = z.object({
  id: z.bigint().optional().meta({ examples: [1] }),
  name: z.string().optional().meta({ examples: ['Dogs'] }),
})

export type CategorySchemaType = z.infer<typeof categorySchema>
```

```typescript [usage.ts]
import { categorySchema, type CategorySchemaType } from './src/gen/zod/categorySchema'

// no import from @kubb/plugin-ts needed, the type comes from the schema
const category: CategorySchemaType = categorySchema.parse({ name: 'Dogs' })
```

Add [`@kubb/plugin-fetch`](/plugins/plugin-fetch/) or [`@kubb/plugin-axios`](/plugins/plugin-axios/) to the same config, and the client keys its `RequestResult` on these inferred types instead of a hand-rolled interface.
