···33description: REST clients for Hey API. Compatible with all our features.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../embed'
88</script>
99
+1-1
docs/openapi-ts/clients/axios.md
···33description: Axios client for Hey API. Compatible with all our features.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../../embed'
88</script>
99
+1-1
docs/openapi-ts/clients/fetch.md
···33description: Fetch API client for Hey API. Compatible with all our features.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../../embed'
88</script>
99
+1-1
docs/openapi-ts/clients/legacy.md
···33description: Legacy clients for Hey API.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../../embed'
88</script>
99
+1-1
docs/openapi-ts/community/spotlight.md
···33description: Meet the people behind @hey-api/openapi-ts.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { VPTeamMembers } from 'vitepress/theme'
88import { coreTeam } from '../../data/coreTeam.js'
99import { hallOfFame } from '../../data/hallOfFame.js'
+1-1
docs/openapi-ts/get-started.md
···33description: Get started with @hey-api/openapi-ts.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../embed'
88</script>
99
+1-1
docs/openapi-ts/plugins/tanstack-query.md
···33description: TanStack Query plugin for Hey API. Compatible with all our features.
44---
5566-<script setup>
66+<script setup lang="ts">
77import { embedProject } from '../../embed'
88</script>
99
+1-1
docs/openapi-ts/plugins/valibot.md
···33description: Valibot plugin for Hey API. Compatible with all our features.
44---
5566-<!-- <script setup>
66+<!-- <script setup lang="ts">
77import { embedProject } from '../../embed'
88</script> -->
99
+8-8
docs/openapi-ts/plugins/zod.md
···33description: Zod plugin for Hey API. Compatible with all our features.
44---
5566-<!-- <script setup>
77-import { embedProject } from '../../embed'
88-</script> -->
99-1010-# Zod
66+<script setup lang="ts">
77+// import { embedProject } from '../../embed'
88+import ZodVersionSwitcher from './zod/ZodVersionSwitcher.vue';
99+</script>
11101212-::: warning
1313-Zod plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues/876).
1414-:::
1111+<div class="heading-with-version">
1212+ <h1>Zod</h1>
1313+ <ZodVersionSwitcher />
1414+</div>
15151616### About
1717
···11+---
22+title: Zod
33+description: Zod plugin for Hey API. Compatible with all our features.
44+---
55+66+<script setup lang="ts">
77+// import { embedProject } from '../../embed'
88+import ZodVersionSwitcher from './ZodVersionSwitcher.vue';
99+</script>
1010+1111+<div class="heading-with-version">
1212+ <h1>Zod</h1>
1313+ <ZodVersionSwitcher />
1414+</div>
1515+1616+### About
1717+1818+[Zod](https://zod.dev) is a TypeScript-first schema validation library with static type inference.
1919+2020+<!-- ### Demo
2121+2222+<button class="buttonLink" @click="(event) => embedProject('hey-api-client-fetch-plugin-zod-example')(event)">
2323+Launch demo
2424+</button> -->
2525+2626+## Features
2727+2828+- seamless integration with `@hey-api/openapi-ts` ecosystem
2929+- Zod schemas for requests, responses, and reusable definitions
3030+3131+## Installation
3232+3333+In your [configuration](/openapi-ts/get-started), add `zod` to your plugins and you'll be ready to generate Zod artifacts. :tada:
3434+3535+```js
3636+export default {
3737+ input: 'https://get.heyapi.dev/hey-api/backend',
3838+ output: 'src/client',
3939+ plugins: [
4040+ // ...other plugins
4141+ 'zod', // [!code ++]
4242+ ],
4343+};
4444+```
4545+4646+### SDKs
4747+4848+To add data validators to your SDKs, set `sdk.validator` to `true`.
4949+5050+```js
5151+export default {
5252+ input: 'https://get.heyapi.dev/hey-api/backend',
5353+ output: 'src/client',
5454+ plugins: [
5555+ // ...other plugins
5656+ 'zod',
5757+ {
5858+ name: '@hey-api/sdk', // [!code ++]
5959+ validator: true, // [!code ++]
6060+ },
6161+ ],
6262+};
6363+```
6464+6565+Learn more about data validators in your SDKs on the [SDKs](/openapi-ts/output/sdk#validators) page.
6666+6767+## Output
6868+6969+The Zod plugin will generate the following artifacts, depending on the input specification.
7070+7171+## Requests
7272+7373+A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers.
7474+7575+::: code-group
7676+7777+```js [config]
7878+export default {
7979+ input: 'https://get.heyapi.dev/hey-api/backend',
8080+ output: 'src/client',
8181+ plugins: [
8282+ // ...other plugins
8383+ {
8484+ name: 'zod',
8585+ requests: true, // [!code ++]
8686+ },
8787+ ],
8888+};
8989+```
9090+9191+```ts [output]
9292+const zData = z.object({
9393+ body: z
9494+ .object({
9595+ foo: z.string().optional(),
9696+ bar: z.union([z.number(), z.null()]).optional(),
9797+ })
9898+ .optional(),
9999+ path: z.object({
100100+ baz: z.string(),
101101+ }),
102102+ query: z.never().optional(),
103103+});
104104+```
105105+106106+:::
107107+108108+::: tip
109109+If you need to access individual fields, you can do so using the [`.shape`](https://zod.dev/api?id=shape) API. For example, we can get the request body schema with `zData.shape.body`.
110110+:::
111111+112112+You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.
113113+114114+## Responses
115115+116116+A single Zod schema is generated for all endpoint's responses. If the endpoint describes multiple responses, the generated schema is a union of all possible response shapes.
117117+118118+::: code-group
119119+120120+```js [config]
121121+export default {
122122+ input: 'https://get.heyapi.dev/hey-api/backend',
123123+ output: 'src/client',
124124+ plugins: [
125125+ // ...other plugins
126126+ {
127127+ name: 'zod',
128128+ responses: true, // [!code ++]
129129+ },
130130+ ],
131131+};
132132+```
133133+134134+```ts [output]
135135+const zResponse = z.union([
136136+ z.object({
137137+ foo: z.string().optional(),
138138+ }),
139139+ z.object({
140140+ bar: z.number().optional(),
141141+ }),
142142+]);
143143+```
144144+145145+:::
146146+147147+You can customize the naming and casing pattern for `responses` schemas using the `.name` and `.case` options.
148148+149149+## Definitions
150150+151151+A Zod schema is generated for every reusable definition from your input.
152152+153153+::: code-group
154154+155155+```js [config]
156156+export default {
157157+ input: 'https://get.heyapi.dev/hey-api/backend',
158158+ output: 'src/client',
159159+ plugins: [
160160+ // ...other plugins
161161+ {
162162+ name: 'zod',
163163+ definitions: true, // [!code ++]
164164+ },
165165+ ],
166166+};
167167+```
168168+169169+```ts [output]
170170+const zFoo = z.number().int();
171171+172172+const zBar = z.object({
173173+ bar: z.array(z.number().int()).optional(),
174174+});
175175+```
176176+177177+:::
178178+179179+You can customize the naming and casing pattern for `definitions` schemas using the `.name` and `.case` options.
180180+181181+## Metadata
182182+183183+It's often useful to associate a schema with some additional [metadata](https://zod.dev/metadata) for documentation, code generation, AI structured outputs, form validation, and other purposes. If this is your use case, you can set `metadata` to `true` to generate additional metadata about schemas.
184184+185185+::: code-group
186186+187187+```js [config]
188188+export default {
189189+ input: 'https://get.heyapi.dev/hey-api/backend',
190190+ output: 'src/client',
191191+ plugins: [
192192+ // ...other plugins
193193+ {
194194+ name: 'zod',
195195+ metadata: true, // [!code ++]
196196+ },
197197+ ],
198198+};
199199+```
200200+201201+```ts [output]
202202+export const zFoo = z.string().describe('Additional metadata');
203203+```
204204+205205+:::
206206+207207+## Types
208208+209209+In addition to Zod schemas, you can generate schema-specific types. These can be generated for all schemas or for specific resources.
210210+211211+::: code-group
212212+213213+```js [config]
214214+export default {
215215+ input: 'https://get.heyapi.dev/hey-api/backend',
216216+ output: 'src/client',
217217+ plugins: [
218218+ // ...other plugins
219219+ {
220220+ name: 'zod',
221221+ types: {
222222+ infer: false, // by default, no `z.infer` types [!code ++]
223223+ },
224224+ responses: {
225225+ types: {
226226+ infer: true, // `z.infer` types only for response schemas [!code ++]
227227+ },
228228+ },
229229+ },
230230+ ],
231231+};
232232+```
233233+234234+```ts [output]
235235+export type ResponseZodType = z.infer<typeof zResponse>;
236236+```
237237+238238+:::
239239+240240+You can customize the naming and casing pattern for schema-specific `types` using the `.name` and `.case` options.
241241+242242+## Config API
243243+244244+You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/zod/types.d.ts) interface.
245245+246246+<!--@include: ../../../partials/examples.md-->
247247+<!--@include: ../../../partials/sponsors.md-->