Skip to content

Commit 3ce5189

Browse files
authored
Merge pull request #2493 from hey-api/docs/zod-datetimes
docs(zod): document iso datetimes
2 parents 75c344d + 4d128d3 commit 3ce5189

File tree

8 files changed

+269
-540
lines changed

8 files changed

+269
-540
lines changed

docs/openapi-ts/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default defineConfig([
6767

6868
You must provide an input so we can load your OpenAPI specification.
6969

70-
The input can be a string path, URL, API registry shorthand, an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
70+
The input can be a string path, URL, [API registry](/openapi-ts/configuration/input#api-registry) shorthand, an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
7171

7272
You can learn more on the [Input](/openapi-ts/configuration/input) page.
7373

docs/openapi-ts/configuration/input.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You must provide an input so we can load your OpenAPI specification.
99

1010
## Input
1111

12-
The input can be a string path, URL, API registry shorthand, an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
12+
The input can be a string path, URL, [API registry](#api-registry), an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
1313

1414
::: code-group
1515

docs/openapi-ts/plugins/zod.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,66 @@ export default {
175175

176176
You can customize the naming and casing pattern for `definitions` schemas using the `.name` and `.case` options.
177177

178+
## ISO Datetimes
179+
180+
By default, values without a timezone or with a timezone offset are not allowed in the `z.iso.datetime()` method.
181+
182+
### Timezone offsets
183+
184+
You can allow values with timezone offsets by setting `dates.offset` to `true`.
185+
186+
::: code-group
187+
188+
```ts [example]
189+
export const zFoo = z.iso.datetime({ offset: true });
190+
```
191+
192+
```js [config]
193+
export default {
194+
input: 'hey-api/backend', // sign up at app.heyapi.dev
195+
output: 'src/client',
196+
plugins: [
197+
// ...other plugins
198+
{
199+
name: 'zod',
200+
dates: {
201+
offset: true, // [!code ++]
202+
},
203+
},
204+
],
205+
};
206+
```
207+
208+
:::
209+
210+
### Local times
211+
212+
You can allow values without a timezone by setting `dates.local` to `true`.
213+
214+
::: code-group
215+
216+
```ts [example]
217+
export const zFoo = z.iso.datetime({ local: true });
218+
```
219+
220+
```js [config]
221+
export default {
222+
input: 'hey-api/backend', // sign up at app.heyapi.dev
223+
output: 'src/client',
224+
plugins: [
225+
// ...other plugins
226+
{
227+
name: 'zod',
228+
dates: {
229+
local: true, // [!code ++]
230+
},
231+
},
232+
],
233+
};
234+
```
235+
236+
:::
237+
178238
## Metadata
179239

180240
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.

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

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export default {
3636
plugins: [
3737
// ...other plugins
3838
{
39-
compatibilityVersion: 'mini', // [!code ++]
4039
name: 'zod', // [!code ++]
40+
compatibilityVersion: 'mini', // [!code ++]
4141
},
4242
],
4343
};
@@ -53,7 +53,10 @@ export default {
5353
output: 'src/client',
5454
plugins: [
5555
// ...other plugins
56-
'zod',
56+
{
57+
name: 'zod',
58+
compatibilityVersion: 'mini',
59+
},
5760
{
5861
name: '@hey-api/sdk', // [!code ++]
5962
validator: true, // [!code ++]
@@ -97,6 +100,7 @@ export default {
97100
// ...other plugins
98101
{
99102
name: 'zod',
103+
compatibilityVersion: 'mini',
100104
requests: true, // [!code ++]
101105
},
102106
],
@@ -136,6 +140,7 @@ export default {
136140
// ...other plugins
137141
{
138142
name: 'zod',
143+
compatibilityVersion: 'mini',
139144
responses: true, // [!code ++]
140145
},
141146
],
@@ -168,6 +173,7 @@ export default {
168173
// ...other plugins
169174
{
170175
name: 'zod',
176+
compatibilityVersion: 'mini',
171177
definitions: true, // [!code ++]
172178
},
173179
],
@@ -178,6 +184,68 @@ export default {
178184

179185
You can customize the naming and casing pattern for `definitions` schemas using the `.name` and `.case` options.
180186

187+
## ISO Datetimes
188+
189+
By default, values without a timezone or with a timezone offset are not allowed in the `z.iso.datetime()` method.
190+
191+
### Timezone offsets
192+
193+
You can allow values with timezone offsets by setting `dates.offset` to `true`.
194+
195+
::: code-group
196+
197+
```ts [example]
198+
export const zFoo = z.iso.datetime({ offset: true });
199+
```
200+
201+
```js [config]
202+
export default {
203+
input: 'hey-api/backend', // sign up at app.heyapi.dev
204+
output: 'src/client',
205+
plugins: [
206+
// ...other plugins
207+
{
208+
name: 'zod',
209+
compatibilityVersion: 'mini',
210+
dates: {
211+
offset: true, // [!code ++]
212+
},
213+
},
214+
],
215+
};
216+
```
217+
218+
:::
219+
220+
### Local times
221+
222+
You can allow values without a timezone by setting `dates.local` to `true`.
223+
224+
::: code-group
225+
226+
```ts [example]
227+
export const zFoo = z.iso.datetime({ local: true });
228+
```
229+
230+
```js [config]
231+
export default {
232+
input: 'hey-api/backend', // sign up at app.heyapi.dev
233+
output: 'src/client',
234+
plugins: [
235+
// ...other plugins
236+
{
237+
name: 'zod',
238+
compatibilityVersion: 'mini',
239+
dates: {
240+
local: true, // [!code ++]
241+
},
242+
},
243+
],
244+
};
245+
```
246+
247+
:::
248+
181249
## Metadata
182250

183251
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.
@@ -198,6 +266,7 @@ export default {
198266
// ...other plugins
199267
{
200268
name: 'zod',
269+
compatibilityVersion: 'mini',
201270
metadata: true, // [!code ++]
202271
},
203272
],
@@ -224,6 +293,7 @@ export default {
224293
// ...other plugins
225294
{
226295
name: 'zod',
296+
compatibilityVersion: 'mini',
227297
types: {
228298
infer: false, // by default, no `z.infer` types [!code ++]
229299
},

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

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export default {
3636
plugins: [
3737
// ...other plugins
3838
{
39-
compatibilityVersion: 3, // [!code ++]
4039
name: 'zod', // [!code ++]
40+
compatibilityVersion: 3, // [!code ++]
4141
},
4242
],
4343
};
@@ -53,7 +53,10 @@ export default {
5353
output: 'src/client',
5454
plugins: [
5555
// ...other plugins
56-
'zod',
56+
{
57+
name: 'zod',
58+
compatibilityVersion: 3,
59+
},
5760
{
5861
name: '@hey-api/sdk', // [!code ++]
5962
validator: true, // [!code ++]
@@ -97,6 +100,7 @@ export default {
97100
// ...other plugins
98101
{
99102
name: 'zod',
103+
compatibilityVersion: 3,
100104
requests: true, // [!code ++]
101105
},
102106
],
@@ -136,6 +140,7 @@ export default {
136140
// ...other plugins
137141
{
138142
name: 'zod',
143+
compatibilityVersion: 3,
139144
responses: true, // [!code ++]
140145
},
141146
],
@@ -168,6 +173,7 @@ export default {
168173
// ...other plugins
169174
{
170175
name: 'zod',
176+
compatibilityVersion: 3,
171177
definitions: true, // [!code ++]
172178
},
173179
],
@@ -178,6 +184,68 @@ export default {
178184

179185
You can customize the naming and casing pattern for `definitions` schemas using the `.name` and `.case` options.
180186

187+
## ISO Datetimes
188+
189+
By default, values without a timezone or with a timezone offset are not allowed in the `z.string().datetime()` method.
190+
191+
### Timezone offsets
192+
193+
You can allow values with timezone offsets by setting `dates.offset` to `true`.
194+
195+
::: code-group
196+
197+
```ts [example]
198+
export const zFoo = z.string().datetime({ offset: true });
199+
```
200+
201+
```js [config]
202+
export default {
203+
input: 'hey-api/backend', // sign up at app.heyapi.dev
204+
output: 'src/client',
205+
plugins: [
206+
// ...other plugins
207+
{
208+
name: 'zod',
209+
compatibilityVersion: 3,
210+
dates: {
211+
offset: true, // [!code ++]
212+
},
213+
},
214+
],
215+
};
216+
```
217+
218+
:::
219+
220+
### Local times
221+
222+
You can allow values without a timezone by setting `dates.local` to `true`.
223+
224+
::: code-group
225+
226+
```ts [example]
227+
export const zFoo = z.string().datetime({ local: true });
228+
```
229+
230+
```js [config]
231+
export default {
232+
input: 'hey-api/backend', // sign up at app.heyapi.dev
233+
output: 'src/client',
234+
plugins: [
235+
// ...other plugins
236+
{
237+
name: 'zod',
238+
compatibilityVersion: 3,
239+
dates: {
240+
local: true, // [!code ++]
241+
},
242+
},
243+
],
244+
};
245+
```
246+
247+
:::
248+
181249
## Metadata
182250

183251
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.
@@ -196,6 +264,7 @@ export default {
196264
// ...other plugins
197265
{
198266
name: 'zod',
267+
compatibilityVersion: 3,
199268
metadata: true, // [!code ++]
200269
},
201270
],
@@ -222,6 +291,7 @@ export default {
222291
// ...other plugins
223292
{
224293
name: 'zod',
294+
compatibilityVersion: 3,
225295
types: {
226296
infer: false, // by default, no `z.infer` types [!code ++]
227297
},

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"sharp": "0.33.5",
19-
"vitepress": "2.0.0-alpha.11",
19+
"vitepress": "2.0.0-alpha.12",
2020
"vitepress-plugin-llms": "1.7.3",
2121
"vue": "3.5.13"
2222
},

0 commit comments

Comments
 (0)