Skip to content

Commit cfd27d6

Browse files
Copilotmrlubos
andcommitted
Update test snapshots for Zod numeric enum support
Co-authored-by: mrlubos <[email protected]>
1 parent cc16cbc commit cfd27d6

File tree

18 files changed

+708
-144
lines changed

18 files changed

+708
-144
lines changed

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

Lines changed: 25 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,9 @@ 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.union([
258+
z.literal(true)
259+
]))
238260
});
239261

240262
/**

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

Lines changed: 25 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,9 @@ export const zModelWithEnum = z.object({
234254
'500 foo.bar',
235255
'600 foo&bar'
236256
]).optional(),
237-
bool: z.unknown().optional()
257+
bool: z.union([
258+
z.literal(true)
259+
]).optional()
238260
});
239261

240262
/**

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

Lines changed: 25 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,9 @@ 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.union([
258+
z.literal(true)
259+
]))
238260
});
239261

240262
/**

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

Lines changed: 48 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,9 @@ 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.union([
340+
z.literal(true)
341+
]))
315342
});
316343

317344
/**
@@ -752,7 +779,9 @@ export const zModelWithConst = z.object({
752779
String: z.optional(z.enum([
753780
'String'
754781
])),
755-
number: z.optional(z.unknown()),
782+
number: z.optional(z.union([
783+
z.literal(0)
784+
])),
756785
null: z.optional(z.unknown()),
757786
withType: z.optional(z.enum([
758787
'Some string'
@@ -938,7 +967,15 @@ export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([
938967
]);
939968

940969
export const zModelWithNumericEnumUnion = z.object({
941-
value: z.optional(z.unknown())
970+
value: z.optional(z.union([
971+
z.literal(-10),
972+
z.literal(-1),
973+
z.literal(0),
974+
z.literal(1),
975+
z.literal(3),
976+
z.literal(6),
977+
z.literal(12)
978+
]))
942979
});
943980

944981
/**

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

Lines changed: 48 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,9 @@ export const zModelWithEnum = z.object({
311336
'500 foo.bar',
312337
'600 foo&bar'
313338
]).optional(),
314-
bool: z.unknown().optional()
339+
bool: z.union([
340+
z.literal(true)
341+
]).optional()
315342
});
316343

317344
/**
@@ -750,7 +777,9 @@ export const zModelWithConst = z.object({
750777
String: z.enum([
751778
'String'
752779
]).optional(),
753-
number: z.unknown().optional(),
780+
number: z.union([
781+
z.literal(0)
782+
]).optional(),
754783
null: z.unknown().optional(),
755784
withType: z.enum([
756785
'Some string'
@@ -936,7 +965,15 @@ export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([
936965
]);
937966

938967
export const zModelWithNumericEnumUnion = z.object({
939-
value: z.unknown().optional()
968+
value: z.union([
969+
z.literal(-10),
970+
z.literal(-1),
971+
z.literal(0),
972+
z.literal(1),
973+
z.literal(3),
974+
z.literal(6),
975+
z.literal(12)
976+
]).optional()
940977
});
941978

942979
/**

0 commit comments

Comments
 (0)