Skip to content

Commit 9954bcf

Browse files
committed
docs: add documentation for Zod 4 and Zod Mini
1 parent 28a006b commit 9954bcf

File tree

5 files changed

+106
-21
lines changed

5 files changed

+106
-21
lines changed

.changeset/mighty-eels-care.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
'@hey-api/openapi-ts': minor
3+
---
4+
5+
feat(zod): add support for Zod 4 and Zod Mini
6+
7+
### Added Zod 4 and Zod Mini
8+
9+
This release adds support for Zod 4 and Zod Mini. By default, the `zod` plugin will generate output for Zod 4. If you want to preserve the previous output for Zod 3 or use Zod Mini, set `compatibilityVersion` to `3` or `mini`.
10+
11+
```js
12+
export default {
13+
input: 'https://get.heyapi.dev/hey-api/backend',
14+
output: 'src/client',
15+
plugins: [
16+
// ...other plugins
17+
{
18+
name: 'zod',
19+
compatibilityVersion: 3,
20+
},
21+
],
22+
};
23+
```
24+
25+
```js
26+
export default {
27+
input: 'https://get.heyapi.dev/hey-api/backend',
28+
output: 'src/client',
29+
plugins: [
30+
// ...other plugins
31+
{
32+
name: 'zod',
33+
compatibilityVersion: 'mini',
34+
},
35+
],
36+
};
37+
```

docs/openapi-ts/migrating.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ description: Migrating to @hey-api/openapi-ts.
77

88
While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues).
99

10+
## v0.80.0
11+
12+
### Added Zod 4 and Zod Mini
13+
14+
This release adds support for Zod 4 and Zod Mini. By default, the `zod` plugin will generate output for Zod 4. If you want to preserve the previous output for Zod 3 or use Zod Mini, set `compatibilityVersion` to `3` or `mini`.
15+
16+
::: code-group
17+
18+
```js [Zod 3]
19+
export default {
20+
input: 'https://get.heyapi.dev/hey-api/backend',
21+
output: 'src/client',
22+
plugins: [
23+
// ...other plugins
24+
{
25+
name: 'zod',
26+
compatibilityVersion: 3, // [!code ++]
27+
},
28+
],
29+
};
30+
```
31+
32+
```js [Zod Mini]
33+
export default {
34+
input: 'https://get.heyapi.dev/hey-api/backend',
35+
output: 'src/client',
36+
plugins: [
37+
// ...other plugins
38+
{
39+
name: 'zod',
40+
compatibilityVersion: 'mini', // [!code ++]
41+
},
42+
],
43+
};
44+
```
45+
46+
:::
47+
1048
## v0.79.0
1149

1250
### Removed `typescript+namespace` enums mode

docs/openapi-ts/plugins/zod.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ export default {
9191
const zData = z.object({
9292
body: z
9393
.object({
94-
foo: z.string().optional(),
95-
bar: z.union([z.number(), z.null()]).optional(),
94+
foo: z.optional(z.string()),
95+
bar: z.optional(z.union([z.number(), z.null()])),
9696
})
9797
.optional(),
9898
path: z.object({
9999
baz: z.string(),
100100
}),
101-
query: z.never().optional(),
101+
query: z.optional(z.never()),
102102
});
103103
```
104104

@@ -133,10 +133,10 @@ export default {
133133
```ts [output]
134134
const zResponse = z.union([
135135
z.object({
136-
foo: z.string().optional(),
136+
foo: z.optional(z.string()),
137137
}),
138138
z.object({
139-
bar: z.number().optional(),
139+
bar: z.optional(z.number()),
140140
}),
141141
]);
142142
```
@@ -166,10 +166,10 @@ export default {
166166
```
167167

168168
```ts [output]
169-
const zFoo = z.number().int();
169+
const zFoo = z.int();
170170

171171
const zBar = z.object({
172-
bar: z.array(z.number().int()).optional(),
172+
bar: z.optional(z.array(z.int())),
173173
});
174174
```
175175

@@ -198,7 +198,9 @@ export default {
198198
```
199199

200200
```ts [output]
201-
export const zFoo = z.string().describe('Additional metadata');
201+
export const zFoo = z.string().register(z.globalRegistry, {
202+
description: 'Additional metadata',
203+
});
202204
```
203205

204206
:::

docs/openapi-ts/plugins/zod/mini.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export default {
3737
output: 'src/client',
3838
plugins: [
3939
// ...other plugins
40-
'zod', // [!code ++]
40+
{
41+
compatibilityVersion: 'mini', // [!code ++]
42+
name: 'zod', // [!code ++]
43+
},
4144
],
4245
};
4346
```
@@ -91,14 +94,14 @@ export default {
9194
const zData = z.object({
9295
body: z
9396
.object({
94-
foo: z.string().optional(),
95-
bar: z.union([z.number(), z.null()]).optional(),
97+
foo: z.optional(z.string()),
98+
bar: z.optional(z.union([z.number(), z.null()])),
9699
})
97100
.optional(),
98101
path: z.object({
99102
baz: z.string(),
100103
}),
101-
query: z.never().optional(),
104+
query: z.optional(z.never()),
102105
});
103106
```
104107

@@ -133,10 +136,10 @@ export default {
133136
```ts [output]
134137
const zResponse = z.union([
135138
z.object({
136-
foo: z.string().optional(),
139+
foo: z.optional(z.string()),
137140
}),
138141
z.object({
139-
bar: z.number().optional(),
142+
bar: z.optional(z.number()),
140143
}),
141144
]);
142145
```
@@ -166,10 +169,10 @@ export default {
166169
```
167170

168171
```ts [output]
169-
const zFoo = z.number().int();
172+
const zFoo = z.int();
170173

171174
const zBar = z.object({
172-
bar: z.array(z.number().int()).optional(),
175+
bar: z.optional(z.array(z.int())),
173176
});
174177
```
175178

@@ -198,7 +201,9 @@ export default {
198201
```
199202

200203
```ts [output]
201-
export const zFoo = z.string().describe('Additional metadata');
204+
export const zFoo = z.string().register(z.globalRegistry, {
205+
description: 'Additional metadata',
206+
});
202207
```
203208

204209
:::

docs/openapi-ts/plugins/zod/v3.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ZodHeading from './ZodHeading.vue';
1414

1515
### About
1616

17-
[Zod](https://zod.dev) is a TypeScript-first schema validation library with static type inference.
17+
[Zod](https://v3.zod.dev/) is a TypeScript-first schema validation library with static type inference.
1818

1919
<!-- ### Demo
2020
@@ -37,7 +37,10 @@ export default {
3737
output: 'src/client',
3838
plugins: [
3939
// ...other plugins
40-
'zod', // [!code ++]
40+
{
41+
compatibilityVersion: 3, // [!code ++]
42+
name: 'zod', // [!code ++]
43+
},
4144
],
4245
};
4346
```
@@ -105,7 +108,7 @@ const zData = z.object({
105108
:::
106109

107110
::: tip
108-
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`.
111+
If you need to access individual fields, you can do so using the [`.shape`](https://v3.zod.dev/?id=shape) API. For example, we can get the request body schema with `zData.shape.body`.
109112
:::
110113

111114
You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.
@@ -179,7 +182,7 @@ You can customize the naming and casing pattern for `definitions` schemas using
179182

180183
## Metadata
181184

182-
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.
185+
It's often useful to associate a schema with some additional [metadata](https://v3.zod.dev/?id=describe) 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.
183186

184187
::: code-group
185188

0 commit comments

Comments
 (0)