File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -179,16 +179,20 @@ z.undefined();
179
179
// => { type: "null" }
180
180
```
181
181
182
- Similarly, ` optional ` and ` nullable ` are made nullable via ` oneOf ` :
182
+ Similarly, ` nullable ` is represented via a union with ` null ` : :
183
183
184
184
``` ts
185
- z .optional (z .string ());
186
- // => { oneOf: [{ type: "string" }, { type: "null" }] }
187
-
188
185
z .nullable (z .string ());
189
186
// => { oneOf: [{ type: "string" }, { type: "null" }] }
190
187
```
191
188
189
+ Optional schemas are represented as-is, though they are decorated with an ` optional ` annotation.
190
+
191
+ ``` ts
192
+ z .optional (z .string ());
193
+ // => { type: "string" }
194
+ ```
195
+
192
196
{ /* ### Pipes
193
197
194
198
Pipes contain and input and and output schema. Zod uses the *output schema* for JSON Schema conversion. */ }
Original file line number Diff line number Diff line change 1
1
import { z } from "zod/v4" ;
2
2
3
- const User = z . object ( {
4
- name : z . string ( ) ,
5
- get friend ( ) {
6
- return User ;
7
- } ,
8
- } ) ;
3
+ const User = z . string ( ) . optional ( ) ;
9
4
10
5
console . dir ( z . toJSONSchema ( User ) , { depth : null } ) ;
11
6
// => {
You can’t perform that action at this time.
0 commit comments