zod
zod copied to clipboard
Support .examples()
JSON Schema supports examples keyword (see https://json-schema.org/draft-06/json-schema-release-notes.html) which is helpful for providing examples of a given schema. While not used for validation, it is very valuable for JSON Schema and OpenAPI documents that could be derived from zod schemas.
Zod already supports .describe(description) command, examples command could work very similarly (.examples(arrayOfExamples))
Nice-to-have - OpenAPI generally describes examples as records (see https://swagger.io/docs/specification/adding-examples/), so supporting any[] is preferable to cover all possible cases.
Just a small addition to @kibertoad suggestion; I think that would be nice to somehow have examples validated against the schema, to prevent wrong examples from being provided
@colinhacks Ping? Any thoughts on this?
I would really appreciate this. functionality like setExamples(examples), addExample(example) and a property like .examples would help within multiple implementations of webframeworks without them all having to do the same thing: adding meta externally.
@kibertoad I created a more formal proposal and a Pull Request. Curious about your opinion.
Bump, I think this is a good feature to bridge the gap between zod and openapi
Bump, would be useful :+1: