omar-dulaimi / prisma-yup-generator

Prisma 2+ generator to emit Yup schemas from your Prisma schema
MIT License
52 stars 3 forks source link

decorator comments to specify validator #3

Open Morriz opened 2 years ago

Morriz commented 2 years ago

Problem

Hi, Prisma only has simple validation for database fields, but Yup/Joi etc allow have richer validators such as email/regex etc. How much work would it be to put the desired validator+args in decorator comments and apply them in the generator to the ones already picked up?

Suggested solution

Example could be:

/// @PrismaYupGen email.nullable
// or 
/// @PrismaYupGen min(1).max(10)

To keep it simple I removed () from validator without args.

Hope to inspire :)

omar-dulaimi commented 2 years ago

Hello @Morriz and thank you for the suggestion.

It actually seems like a great addition to the library. I'll give it a try soon to see if I could implement it with the current state of the project.

I'll let you know soon :)

Morriz commented 2 years ago

Awesome! By the way, maybe the namespace could be @PrismaValGen to keep it generic, but only if it is possible to express the validators generically of course. It might be a headache to map them to the respective adapters

Morriz commented 2 years ago

Any updates here? Did you maybe try to create a PoC for this?

omar-dulaimi commented 2 years ago

Unfortunately, I hadn't had a chance to, and not sure if I will anytime soon.

So if you feel adventurous, you can work on it. I'll answer any questions you have.