Skip to content
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

Passing arguments to "z.string()" #142

Open
PlayWolfYT opened this issue Aug 8, 2022 · 2 comments
Open

Passing arguments to "z.string()" #142

PlayWolfYT opened this issue Aug 8, 2022 · 2 comments

Comments

@PlayWolfYT
Copy link

It would be nice to have the possibility to pass arguments to the z.string() function.
This would be useful to, for example, set the required_error option to some better message than just the default "Required"

One way of doing that could maybe look like this:

model User {
  id        String   @id @default(uuid())

  /// @zod {required_error: "Please enter a name"}
  name      String
}

which would generate the following

export const UserModel = z.object({
  id: z.string(),
  name: z.string({ required_error: "Please enter a name" })
});
@mainshum
Copy link

@PlayWolfYT have you found any of doing that eventually?

@mainshum
Copy link

mainshum commented Oct 20, 2023

I've got this:
/// @zod.custom(z.string({required_error: "Some error message"}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants