You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/create/schema/override.test.ts
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,23 @@ import { validate } from './override.js';
5
5
6
6
describe('validate',()=>{
7
7
it('should throw an error for a custom optional',()=>{
8
+
constcustom=z.custom();
8
9
expect(()=>
9
10
validate(
10
11
{
11
-
zodSchema: z.custom().optional(),
12
+
zodSchema: custom.optional(),
12
13
jsonSchema: {},
13
14
io: 'input',
14
15
path: ['properties','zodOpenApiCreateSchema'],
15
16
},
16
17
{},
18
+
{
19
+
context: {
20
+
jsonSchema: {},
21
+
zodSchema: custom,
22
+
path: ['properties','zodOpenApiCreateSchema'],
23
+
},
24
+
},
17
25
),
18
26
).toThrowErrorMatchingInlineSnapshot(
19
27
`[Error: Zod schema of type \`custom\` at properties > zodOpenApiCreateSchema cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\`]`,
@@ -30,6 +38,7 @@ describe('validate', () => {
30
38
path: ['properties','zodOpenApiCreateSchema'],
31
39
},
32
40
{},
41
+
{},
33
42
),
34
43
).toThrow(
35
44
'Zod schema of type `void` at properties > zodOpenApiCreateSchema cannot be represented in OpenAPI. Please assign it metadata with `.meta()`',
@@ -46,6 +55,7 @@ describe('validate', () => {
46
55
path: ['properties','zodOpenApiCreateSchema'],
47
56
},
48
57
{},
58
+
{},
49
59
),
50
60
).toThrow(
51
61
'Zod schema of type `map` at properties > zodOpenApiCreateSchema cannot be represented in OpenAPI. Please assign it metadata with `.meta()`',
// For some reason transform calls pipe and the meta ends up on the pipe instead of the transform
108
+
thrownewError(
109
+
`Zod transform found at ${previousContext.context.path.join(' > ')} are not supported in output schemas. Please use \`.overwrite()\` or wrap the schema in a \`.pipe()\` or assign it manual metadata with \`.meta()\``,
110
+
);
111
+
}
112
+
113
+
thrownewError(
114
+
`Zod schema of type \`${previousContext.context.zodSchema._zod.def.type}\` at ${previousContext.context?.path.join(' > ')} cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\``,
115
+
);
116
+
}
117
+
118
+
previousContext.context=undefined;
119
+
99
120
if(Object.keys(ctx.jsonSchema).length){
100
121
return;
101
122
}
@@ -115,6 +136,7 @@ export const validate = (
115
136
zodSchema: def.innerType,
116
137
}asZodOpenApiOverrideContext,
117
138
opts,
139
+
previousContext,
118
140
);
119
141
return;
120
142
}
@@ -126,10 +148,14 @@ export const validate = (
126
148
}
127
149
case'pipe': {
128
150
if(ctx.io==='output'){
129
-
// For some reason transform calls pipe and the meta ends up on the pipe instead of the transform
130
-
thrownewError(
131
-
`Zod transform found at ${ctx.path.join(' > ')} are not supported in output schemas. Please use \`.overwrite()\` or wrap the schema in a \`.pipe()\` or assign it manual metadata with \`.meta()\``,
132
-
);
151
+
if(!ctx.zodSchema._zod.parent){
152
+
previousContext.context=ctx;
153
+
return;
154
+
}
155
+
// // For some reason transform calls pipe and the meta ends up on the pipe instead of the transform
156
+
// throw new Error(
157
+
// `Zod transform found at ${ctx.path.join(' > ')} are not supported in output schemas. Please use \`.overwrite()\` or wrap the schema in a \`.pipe()\` or assign it manual metadata with \`.meta()\``,
0 commit comments