You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've considered asking this for a bit, for the sake of trpc-cli. So far, it takes advantage of .describe('...') to allow adding CLI docs for zod input parameters, but it would be nice to add richer metadata.
How I think it could work:
Define a new ZodMeta interface (maybe make it generic with the same typeargs as ZodType)
Only add a description property to it
Add a metadata: ZodMeta prop to ZodType
Have .describe('foo') update the metadata to { description: 'foo' } (maybe shallow-merging the old value?)
Update the description property of ZodType to get description() { return this.metadata.description } for backwards-compatibility
The fun part would be: end users could then use module augmentation to add to ZodMeta however they like, e.g. I in trpc-cli could do:
import{z}from'zod'declare module 'zod'{exportinterfaceZodMeta{alias: string}}constrouter=t.router({test: t.input(z.object({glob: z.string().meta({description: 'Glob pattern for test files',alias: 'g',})})).mutation(...))
Looking at the issues, I think this would cover a few requests zod has got:
Possible more but I didn't go that far back in the issues. In general, with trpc and OpenAI adopting zod, there will be more cases where people use zod as a user-facing part of their libraries and applications, so there might be more and more requests for the ability to attach metadat to types
Alternatively, these fields could somehow be dumped onto ZodDef, which is where description lives now but that doesn't feel quite right to me.
The text was updated successfully, but these errors were encountered:
I've considered asking this for a bit, for the sake of trpc-cli. So far, it takes advantage of
.describe('...')
to allow adding CLI docs for zod input parameters, but it would be nice to add richer metadata.How I think it could work:
ZodMeta
interface (maybe make it generic with the same typeargs asZodType
)description
property to itmetadata: ZodMeta
prop toZodType
.describe('foo')
update the metadata to{ description: 'foo' }
(maybe shallow-merging the old value?)get description() { return this.metadata.description }
for backwards-compatibilityThe fun part would be: end users could then use module augmentation to add to
ZodMeta
however they like, e.g. I in trpc-cli could do:Looking at the issues, I think this would cover a few requests zod has got:
#3734
#3732
#3736 (maybe)
#3673
#1439
Possible more but I didn't go that far back in the issues. In general, with trpc and OpenAI adopting zod, there will be more cases where people use zod as a user-facing part of their libraries and applications, so there might be more and more requests for the ability to attach metadat to types
Alternatively, these fields could somehow be dumped onto
ZodDef
, which is wheredescription
lives now but that doesn't feel quite right to me.The text was updated successfully, but these errors were encountered: