[Feature Request]: Meta data/labels
See original GitHub issueI saw this being mentioned before in another issue, but I’d like to make the request again with a slightly different user story.
My team is looking at replacing Joi with ZodV2 in its Hapi microservice. We really like that we can create an input validation for a handler, and have it tightly coupled to the handler’s input’s type definition. So there is no more worrying about, “Oh, is the validation wrong, or is the input’s typing wrong”. Its the same.
The only loose thread is documentation. We want to create something that parses our Hapi route objects, sees the Zod object we have passed to the validator, and generates a documentation page for that route.
Simply parsing the ZodObject isn’t quite cutting it. It ends up lacking information and context that we’d like, between refinements, transformations, and things that we just want to have more explanation on. If individual Zod elements could have a .label
or a .meta
property, it’d give us a bit more flexibility in creating documentation that is tightly coupled with our zod schema.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:8 (1 by maintainers)
Top GitHub Comments
What I was imagining he had done was something like this:
Run with Codesandbox.io
But this isn’t really possible unfortunately.
As I’ve suggested in other issues, I recommend doing this by wrapping Zod.
Bringing this inside Zod is a huge footgun and encourages lots of anti-patterns that would be better solved by either creating higher-level constructs that include a Zod schema (like
MyEndpoint
) or using factory/generator functions that return a schema.