Skip to content

Commit 0a9bb68

Browse files
authored
Merge pull request #3552 from erikwski/main
fix(zod): support `guid` format in Zod v4/mini
2 parents 44ce085 + 08d9909 commit 0a9bb68

9 files changed

Lines changed: 74 additions & 0 deletions

File tree

.changeset/cyan-boats-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(zod)**: handle `guid` string format
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as z from 'zod/mini';
4+
5+
export const zGetFooData = z.object({
6+
body: z.optional(z.never()),
7+
path: z.object({
8+
guidId: z.guid()
9+
}),
10+
query: z.optional(z.never())
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod/v3';
4+
5+
export const zGetFooData = z.object({
6+
body: z.never().optional(),
7+
path: z.object({
8+
guidId: z.string()
9+
}),
10+
query: z.never().optional()
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as z from 'zod';
4+
5+
export const zGetFooData = z.object({
6+
body: z.never().optional(),
7+
path: z.object({
8+
guidId: z.guid()
9+
}),
10+
query: z.never().optional()
11+
});

packages/openapi-ts-tests/zod/v4/test/formats.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ for (const zodVersion of zodVersions) {
4646
}),
4747
description: 'generates anyOf string and binary string',
4848
},
49+
{
50+
config: createConfig({
51+
input: 'string-with-guid-format.yaml',
52+
output: 'string-with-guid-format',
53+
plugins: [
54+
{
55+
compatibilityVersion: zodVersion.compatibilityVersion,
56+
name: 'zod',
57+
},
58+
],
59+
}),
60+
description: 'handles string guid format',
61+
},
4962
];
5063

5164
it.each(scenarios)('$description', async ({ config }) => {

packages/openapi-ts/src/plugins/zod/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const identifiers = {
2020
globalRegistry: 'globalRegistry',
2121
gt: 'gt',
2222
gte: 'gte',
23+
guid: 'guid',
2324
infer: 'infer',
2425
int: 'int',
2526
intersection: 'intersection',

packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function formatNode(ctx: StringResolverContext): ChainResult {
3636
}
3737
case 'email':
3838
return $(z).attr(identifiers.email).call();
39+
case 'guid':
40+
return $(z).attr(identifiers.guid).call();
3941
case 'ipv4':
4042
return $(z).attr(identifiers.ipv4).call();
4143
case 'ipv6':

packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function formatNode(ctx: StringResolverContext): ChainResult {
3636
}
3737
case 'email':
3838
return $(z).attr(identifiers.email).call();
39+
case 'guid':
40+
return $(z).attr(identifiers.guid).call();
3941
case 'ipv4':
4042
return $(z).attr(identifiers.ipv4).call();
4143
case 'ipv6':
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
openapi: 3.1.1
2+
info:
3+
title: OpenAPI 3.1.1 string with GUID format example
4+
version: '1'
5+
paths:
6+
/foo/{guidId}:
7+
get:
8+
operationId: getFoo
9+
parameters:
10+
- name: guidId
11+
in: path
12+
required: true
13+
schema:
14+
type: string
15+
format: guid
16+
responses:
17+
'200':
18+
description: OK

0 commit comments

Comments
 (0)