Skip to content

Commit 44ccd36

Browse files
authored
Merge pull request #2704 from hey-api/copilot/fix-f5d17ffa-a1b7-42cb-856a-d2277e88e4fe
2 parents 612d9c1 + a0cd0fd commit 44ccd36

File tree

23 files changed

+901
-197
lines changed

23 files changed

+901
-197
lines changed

.changeset/small-numbers-pull.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+
fix(zod): correct schemas for numeric and boolean enums

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,21 @@ export const zSessionUserRoomSystemCalloutFailedWebhookRequest = z.object({
630630
host_id: z.string(),
631631
message_id: z.string(),
632632
inviter_name: z.string(),
633-
reason_type: z.unknown(),
633+
reason_type: z.union([
634+
z.literal(0),
635+
z.literal(1),
636+
z.literal(2),
637+
z.literal(3),
638+
z.literal(4),
639+
z.literal(7),
640+
z.literal(8),
641+
z.literal(9),
642+
z.literal(10),
643+
z.literal(11),
644+
z.literal(12),
645+
z.literal(13),
646+
z.literal(14)
647+
]),
634648
participant: z.object({
635649
call_type: z.string(),
636650
device_ip: z.string()

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ export const zEnumWithStrings = z.enum([
103103
/**
104104
* This is a simple enum with numbers
105105
*/
106-
export const zEnumWithNumbers = z.unknown();
106+
export const zEnumWithNumbers = z.union([
107+
z.literal(1),
108+
z.literal(2),
109+
z.literal(3),
110+
z.literal(1.1),
111+
z.literal(1.2),
112+
z.literal(1.3),
113+
z.literal(100),
114+
z.literal(200),
115+
z.literal(300),
116+
z.literal(-100),
117+
z.literal(-200),
118+
z.literal(-300),
119+
z.literal(-1.1),
120+
z.literal(-1.2),
121+
z.literal(-1.3)
122+
]);
107123

108124
/**
109125
* Success=1,Warning=2,Error=3
@@ -113,7 +129,11 @@ export const zEnumFromDescription = z.number();
113129
/**
114130
* This is a simple enum with numbers
115131
*/
116-
export const zEnumWithExtensions = z.unknown();
132+
export const zEnumWithExtensions = z.union([
133+
z.literal(200),
134+
z.literal(400),
135+
z.literal(500)
136+
]);
117137

118138
/**
119139
* This is a simple array with numbers
@@ -234,7 +254,7 @@ export const zModelWithEnum = z.object({
234254
'500 foo.bar',
235255
'600 foo&bar'
236256
])),
237-
bool: z.optional(z.unknown())
257+
bool: z.optional(z.literal(true))
238258
});
239259

240260
/**

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ export const zEnumWithStrings = z.enum([
103103
/**
104104
* This is a simple enum with numbers
105105
*/
106-
export const zEnumWithNumbers = z.unknown();
106+
export const zEnumWithNumbers = z.union([
107+
z.literal(1),
108+
z.literal(2),
109+
z.literal(3),
110+
z.literal(1.1),
111+
z.literal(1.2),
112+
z.literal(1.3),
113+
z.literal(100),
114+
z.literal(200),
115+
z.literal(300),
116+
z.literal(-100),
117+
z.literal(-200),
118+
z.literal(-300),
119+
z.literal(-1.1),
120+
z.literal(-1.2),
121+
z.literal(-1.3)
122+
]);
107123

108124
/**
109125
* Success=1,Warning=2,Error=3
@@ -113,7 +129,11 @@ export const zEnumFromDescription = z.number();
113129
/**
114130
* This is a simple enum with numbers
115131
*/
116-
export const zEnumWithExtensions = z.unknown();
132+
export const zEnumWithExtensions = z.union([
133+
z.literal(200),
134+
z.literal(400),
135+
z.literal(500)
136+
]);
117137

118138
/**
119139
* This is a simple array with numbers
@@ -234,7 +254,7 @@ export const zModelWithEnum = z.object({
234254
'500 foo.bar',
235255
'600 foo&bar'
236256
]).optional(),
237-
bool: z.unknown().optional()
257+
bool: z.literal(true).optional()
238258
});
239259

240260
/**

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ export const zEnumWithStrings = z.enum([
103103
/**
104104
* This is a simple enum with numbers
105105
*/
106-
export const zEnumWithNumbers = z.unknown();
106+
export const zEnumWithNumbers = z.union([
107+
z.literal(1),
108+
z.literal(2),
109+
z.literal(3),
110+
z.literal(1.1),
111+
z.literal(1.2),
112+
z.literal(1.3),
113+
z.literal(100),
114+
z.literal(200),
115+
z.literal(300),
116+
z.literal(-100),
117+
z.literal(-200),
118+
z.literal(-300),
119+
z.literal(-1.1),
120+
z.literal(-1.2),
121+
z.literal(-1.3)
122+
]);
107123

108124
/**
109125
* Success=1,Warning=2,Error=3
@@ -113,7 +129,11 @@ export const zEnumFromDescription = z.number();
113129
/**
114130
* This is a simple enum with numbers
115131
*/
116-
export const zEnumWithExtensions = z.unknown();
132+
export const zEnumWithExtensions = z.union([
133+
z.literal(200),
134+
z.literal(400),
135+
z.literal(500)
136+
]);
117137

118138
/**
119139
* This is a simple array with numbers
@@ -234,7 +254,7 @@ export const zModelWithEnum = z.object({
234254
'500 foo.bar',
235255
'600 foo&bar'
236256
])),
237-
bool: z.optional(z.unknown())
257+
bool: z.optional(z.literal(true))
238258
});
239259

240260
/**

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,34 @@ export const zEnumWithStrings = z.enum([
119119
'Non-ascii: øæåôöØÆÅÔÖ字符串'
120120
]);
121121

122-
export const zEnumWithReplacedCharacters = z.enum([
123-
"'Single Quote'",
124-
'"Double Quotes"',
125-
'øæåôöØÆÅÔÖ字符串',
126-
''
122+
export const zEnumWithReplacedCharacters = z.union([
123+
z.literal("'Single Quote'"),
124+
z.literal('"Double Quotes"'),
125+
z.literal('øæåôöØÆÅÔÖ字符串'),
126+
z.literal(3.1),
127+
z.literal('')
127128
]);
128129

129130
/**
130131
* This is a simple enum with numbers
131132
*/
132-
export const zEnumWithNumbers = z.unknown();
133+
export const zEnumWithNumbers = z.union([
134+
z.literal(1),
135+
z.literal(2),
136+
z.literal(3),
137+
z.literal(1.1),
138+
z.literal(1.2),
139+
z.literal(1.3),
140+
z.literal(100),
141+
z.literal(200),
142+
z.literal(300),
143+
z.literal(-100),
144+
z.literal(-200),
145+
z.literal(-300),
146+
z.literal(-1.1),
147+
z.literal(-1.2),
148+
z.literal(-1.3)
149+
]);
133150

134151
/**
135152
* Success=1,Warning=2,Error=3
@@ -139,9 +156,17 @@ export const zEnumFromDescription = z.number();
139156
/**
140157
* This is a simple enum with numbers
141158
*/
142-
export const zEnumWithExtensions = z.unknown();
159+
export const zEnumWithExtensions = z.union([
160+
z.literal(200),
161+
z.literal(400),
162+
z.literal(500)
163+
]);
143164

144-
export const zEnumWithXEnumNames = z.unknown();
165+
export const zEnumWithXEnumNames = z.union([
166+
z.literal(0),
167+
z.literal(1),
168+
z.literal(2)
169+
]);
145170

146171
/**
147172
* This is a simple array with numbers
@@ -311,7 +336,7 @@ export const zModelWithEnum = z.object({
311336
'500 foo.bar',
312337
'600 foo&bar'
313338
])),
314-
bool: z.optional(z.unknown())
339+
bool: z.optional(z.literal(true))
315340
});
316341

317342
/**
@@ -752,7 +777,7 @@ export const zModelWithConst = z.object({
752777
String: z.optional(z.enum([
753778
'String'
754779
])),
755-
number: z.optional(z.unknown()),
780+
number: z.optional(z.literal(0)),
756781
null: z.optional(z.unknown()),
757782
withType: z.optional(z.enum([
758783
'Some string'
@@ -938,7 +963,15 @@ export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([
938963
]);
939964

940965
export const zModelWithNumericEnumUnion = z.object({
941-
value: z.optional(z.unknown())
966+
value: z.optional(z.union([
967+
z.literal(-10),
968+
z.literal(-1),
969+
z.literal(0),
970+
z.literal(1),
971+
z.literal(3),
972+
z.literal(6),
973+
z.literal(12)
974+
]))
942975
});
943976

944977
/**

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,34 @@ export const zEnumWithStrings = z.enum([
119119
'Non-ascii: øæåôöØÆÅÔÖ字符串'
120120
]);
121121

122-
export const zEnumWithReplacedCharacters = z.enum([
123-
"'Single Quote'",
124-
'"Double Quotes"',
125-
'øæåôöØÆÅÔÖ字符串',
126-
''
122+
export const zEnumWithReplacedCharacters = z.union([
123+
z.literal("'Single Quote'"),
124+
z.literal('"Double Quotes"'),
125+
z.literal('øæåôöØÆÅÔÖ字符串'),
126+
z.literal(3.1),
127+
z.literal('')
127128
]);
128129

129130
/**
130131
* This is a simple enum with numbers
131132
*/
132-
export const zEnumWithNumbers = z.unknown();
133+
export const zEnumWithNumbers = z.union([
134+
z.literal(1),
135+
z.literal(2),
136+
z.literal(3),
137+
z.literal(1.1),
138+
z.literal(1.2),
139+
z.literal(1.3),
140+
z.literal(100),
141+
z.literal(200),
142+
z.literal(300),
143+
z.literal(-100),
144+
z.literal(-200),
145+
z.literal(-300),
146+
z.literal(-1.1),
147+
z.literal(-1.2),
148+
z.literal(-1.3)
149+
]);
133150

134151
/**
135152
* Success=1,Warning=2,Error=3
@@ -139,9 +156,17 @@ export const zEnumFromDescription = z.number();
139156
/**
140157
* This is a simple enum with numbers
141158
*/
142-
export const zEnumWithExtensions = z.unknown();
159+
export const zEnumWithExtensions = z.union([
160+
z.literal(200),
161+
z.literal(400),
162+
z.literal(500)
163+
]);
143164

144-
export const zEnumWithXEnumNames = z.unknown();
165+
export const zEnumWithXEnumNames = z.union([
166+
z.literal(0),
167+
z.literal(1),
168+
z.literal(2)
169+
]);
145170

146171
/**
147172
* This is a simple array with numbers
@@ -311,7 +336,7 @@ export const zModelWithEnum = z.object({
311336
'500 foo.bar',
312337
'600 foo&bar'
313338
]).optional(),
314-
bool: z.unknown().optional()
339+
bool: z.literal(true).optional()
315340
});
316341

317342
/**
@@ -750,7 +775,7 @@ export const zModelWithConst = z.object({
750775
String: z.enum([
751776
'String'
752777
]).optional(),
753-
number: z.unknown().optional(),
778+
number: z.literal(0).optional(),
754779
null: z.unknown().optional(),
755780
withType: z.enum([
756781
'Some string'
@@ -936,7 +961,15 @@ export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([
936961
]);
937962

938963
export const zModelWithNumericEnumUnion = z.object({
939-
value: z.unknown().optional()
964+
value: z.union([
965+
z.literal(-10),
966+
z.literal(-1),
967+
z.literal(0),
968+
z.literal(1),
969+
z.literal(3),
970+
z.literal(6),
971+
z.literal(12)
972+
]).optional()
940973
});
941974

942975
/**

0 commit comments

Comments
 (0)