diff --git a/README.md b/README.md index 55a24a12f..57531084d 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ - [.superRefine](#superRefine) - [.transform](#transform) - [.default](#default) + - [.describe](#describe) - [.catch](#catch) - [.optional](#optional) - [.nullable](#nullable) @@ -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. diff --git a/deno/lib/README.md b/deno/lib/README.md index d0a97ea10..49f747e9c 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -102,6 +102,7 @@ - [.superRefine](#superRefine) - [.transform](#transform) - [.default](#default) + - [.describe](#describe) - [.catch](#catch) - [.optional](#optional) - [.nullable](#nullable) @@ -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.