colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

Add title field to Zod - close #1831 #3595

Open ComBarnea opened 2 months ago

ComBarnea commented 2 months ago

Title is a useful field when presenting or converting to JSON schema. Title is used for a human-readable name of a variable. Very practical when combined with description.

Add optional title field. Add titled setter method. Add test suit. Update docs next to describe for ease of use.

netlify[bot] commented 2 months ago

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit a7389059e7f0c122e6d111187a48a3bee22fd43c
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/667b18f7cf350500087c6ef7
Deploy Preview https://deploy-preview-3595--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

ComBarnea commented 2 months ago

One note about this: I was unsure if I should use the name of titled or title. I think title have a better DX, but looking at all other methods, seems like description is following another pattern with describe so I tried to follow the same pattern.

ComBarnea commented 2 months ago

Hey @colinhacks, any chance you can check this out? We are adding Zod to Novu, and I'd love to have this title available. I am happy to add more information if this can be helpful.

Thanks!

lxcid commented 2 months ago

Hey, wanna give a +1 to this PR. title indeed is useful and its part of the annotation keyword in JSON schema.

https://json-schema.org/understanding-json-schema/reference/annotations

lxcid commented 1 month ago

To help advocate for this PR further, in OpenAI latest recommendation on data structure for json schema response at https://platform.openai.com/docs/guides/structured-outputs/tips-for-your-data-structure

CleanShot 2024-08-07 at 14 19 24@2x

They mentioned about defining title as one of the tip.

In pydantic (zod equivalent in python), they do allow defining title in field:

https://docs.pydantic.dev/latest/api/fields/#pydantic.fields.Field

CleanShot 2024-08-07 at 14 18 44@2x