StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
886 stars 71 forks source link

Would it be possible to retain branded types? #114

Closed ConnorSinnott closed 5 months ago

ConnorSinnott commented 6 months ago

Howdy! I understand that the branding system doesn't really exist at runtime, but there could be value in adding wrappers which enable the JSON ser/de to retain the brands. Something along the line of zodToJsonSchemaBranded('my-brand', z.___.brand()) where zodToJsonSchemaBranded<T extends string>(brand: T, schema: z.ZodBranded<T>). I think it could be possible for inner .brand function to infer the string from the wrapper.

StefanTerdell commented 5 months ago

Hi! Thanks for opening an issue. I'm hesitant to expanding the API for this. Perhaps use the override feature?

StefanTerdell commented 5 months ago

Closing for now! Feel free to reopen if it doesn't work out.

ConnorSinnott commented 5 months ago

No problem! Thanks for the support!