Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document .describe() #1819

Merged
merged 2 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- [.superRefine](#superRefine)
- [.transform](#transform)
- [.default](#default)
- [.describe](#describe)
- [.catch](#catch)
- [.optional](#optional)
- [.nullable](#nullable)
Expand Down Expand Up @@ -2047,6 +2048,17 @@ Conceptually, this is how Zod processes default values:
1. If the input is `undefined`, the default value is returned
2. Otherwise, the data is parsed using the base schema

### `.describe`

Use `.describe()` to add a `description` property to the resulting schema.

```ts
const documentedString = z.string().describe("A useful bit of text, if you know what to do with it.");
documentedString.description // A useful bit of text…
```

This can be useful for documenting a field, for example in a JSON Schema using a library like [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema)).

### `.catch`

Use `.catch()` to provide a "catch value" to be returned in the event of a parsing error.
Expand Down
12 changes: 12 additions & 0 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- [.superRefine](#superRefine)
- [.transform](#transform)
- [.default](#default)
- [.describe](#describe)
- [.catch](#catch)
- [.optional](#optional)
- [.nullable](#nullable)
Expand Down Expand Up @@ -2047,6 +2048,17 @@ Conceptually, this is how Zod processes default values:
1. If the input is `undefined`, the default value is returned
2. Otherwise, the data is parsed using the base schema

### `.describe`

Use `.describe()` to add a `description` property to the resulting schema.

```ts
const documentedString = z.string().describe("A useful bit of text, if you know what to do with it.");
documentedString.description // A useful bit of text…
```

This can be useful for documenting a field, for example in a JSON Schema using a library like [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema)).

### `.catch`

Use `.catch()` to provide a "catch value" to be returned in the event of a parsing error.
Expand Down