From 5b400006e5bcd5d12f5e01ee8d5b6c3d97119954 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 4 Jan 2023 22:29:54 -0500 Subject: [PATCH 1/2] Document `.describe()` https://github.com/colinhacks/zod/issues/1443 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 55a24a12f..0f3b8a7b6 100644 --- a/README.md +++ b/README.md @@ -2047,6 +2047,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. From 39ab7e2825030acd2c64ff14408a83e807c3b3b7 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Fri, 6 Jan 2023 19:51:25 -0500 Subject: [PATCH 2/2] PR Feedback --- README.md | 3 ++- deno/lib/README.md | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f3b8a7b6..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) @@ -2056,7 +2057,7 @@ const documentedString = z.string().describe("A useful bit of text, if you know 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)). +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` 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.