Skip to content

Commit 947b4eb

Browse files
committed
Document z.meta and z.describe
1 parent a526e78 commit 947b4eb

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

packages/docs/content/metadata.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ const emailSchema = z.email().meta({
135135
</Tab>
136136
<Tab value="Zod Mini">
137137
```ts
138-
// no equivalent
139-
140-
138+
const emailSchema = z.email().check(
139+
z.meta({
140+
id: "email_address",
141+
title: "Email address",
142+
description: "Please enter a valid email address",
143+
})
144+
);
141145
```
142146
</Tab>
143147
</Tabs>
@@ -181,11 +185,10 @@ emailSchema.meta({ description: "An email address" });
181185
</Tab>
182186
<Tab value="Zod Mini">
183187
```ts
184-
// no equivalent
185-
186-
187-
188-
188+
const emailSchema = z.email().check(z.describe("An email address"));
189+
190+
// equivalent to
191+
z.email().check(z.meta({ description: "An email address" }));
189192
```
190193
</Tab>
191194
</Tabs>

packages/docs/content/packages/mini.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ z.normalize();
191191
z.trim();
192192
z.toLowerCase();
193193
z.toUpperCase();
194+
195+
// metadata (registers schema in z.globalRegistry)
196+
z.meta({ title: "...", description: "..." });
197+
z.describe("...");
194198
```
195199

196200
### `.register()`

play.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,24 @@ import * as z from "zod";
33
z.string().brand<"A", "in">();
44
z.string().brand<"A", "out">();
55
z.string().brand<"A", "inout">();
6+
7+
const baseSchema = z.object({
8+
value: z.number(),
9+
allowsNegative: z.boolean(),
10+
somethingElse: z.string(),
11+
});
12+
13+
const refinement = z.refine<{ value: number; allowsNegative: boolean }>(({ value, allowsNegative }) => {
14+
if (allowsNegative) {
15+
return true;
16+
}
17+
return value >= 0;
18+
});
19+
20+
const schema = baseSchema.check(refinement);
21+
22+
const schemaB = baseSchema
23+
.safeOmit({
24+
somethingElse: true,
25+
})
26+
.check(refinement);

0 commit comments

Comments
 (0)