colinhacks / zod

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

Support `enumDescriptions` #3673

Open remcohaszing opened 1 month ago

remcohaszing commented 1 month ago

The VSCode JSON schema integration supports a custom field enumDescriptions to describe each enum value individually. This is used by various other editors as well. It would be neat if Zod supports this field too, for example:

const kin = z
  .enum([
    'elf',
    'dwarf',
    'human'
  ])
  .describe('Your character lineage', [
    'Elves are a magical people of otherworldly grace',
    'Bold and hardy, dwarves are known as skilled warriors, miners, and workers of stone and metal',
    'Humans are the most adaptable and ambitious people among the common kin'
  ])

console.log(kin.enumDescriptions)
// [
//   'Elves are a magical people of otherworldly grace',
//   'Bold and hardy, dwarves are known as skilled warriors, miners, and workers of stone and metal',
//   'Humans are the most adaptable and ambitious people among the common kin'
// ]