-
-
Notifications
You must be signed in to change notification settings - Fork 664
feat: add option to inject params in generated zod schemas #3475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -744,6 +744,18 @@ export interface ZodOptions { | |
| body?: Mutator; | ||
| response?: Mutator; | ||
| }; | ||
| /** | ||
| * Mutator referencing a function called once per emitted validator at schema | ||
| * construction time. It receives codegen-time context (operation, location, | ||
| * schema name, field path, validator name) and returns a Zod `params` object | ||
| * (e.g. `{ error: ... }`) that is appended as the trailing argument. | ||
| * | ||
| * The plural name follows Zod's own term for the validator's second argument | ||
| * (`z.string(params)`) and is unrelated to the singular `param` key used by | ||
| * `generate` / `coerce` / `preprocess` above, which refers to the path-parameter | ||
| * location. | ||
| */ | ||
| params?: Mutator; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny naming flag (defer to you):
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarified in the docs as I would like to keep the zod semantics here |
||
| dateTimeOptions?: ZodDateTimeOptions; | ||
| timeOptions?: ZodTimeOptions; | ||
| generateEachHttpStatus?: boolean; | ||
|
|
@@ -802,6 +814,7 @@ export interface NormalizedZodOptions { | |
| body?: NormalizedMutator; | ||
| response?: NormalizedMutator; | ||
| }; | ||
| params?: NormalizedMutator; | ||
| generateEachHttpStatus: boolean; | ||
| useBrandedTypes: boolean; | ||
| generateReusableSchemas: boolean; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
{ error }shape is zod v4-only. orval supports both v3 and v4 and this injection runs on both paths, but I checked against zod 3.25.76 / 4.3.6: on v3{ error }is silently ignored — no build- or parse-time error, the message just stays the default (.email({ error: 'x' })→"Invalid email").{ message }works on both. Might be worth a one-liner noting the v3/v4 difference and suggesting{ message }for anyone supporting both versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a section to the docs to specify this