omar-dulaimi / prisma-class-validator-generator

Prisma 2+ generator to emit typescript models of your database with class validator
MIT License
65 stars 11 forks source link

Swagger implementation #18

Open jannis6023 opened 1 week ago

jannis6023 commented 1 week ago

Problem

I use Prisma in combination with NestJS. There, I use the swagger implementation which is also based on decorators. Currently, I would have to add the class-validator decorators after generating my classes for swagger using prisma-class-generator. On re-generation, I would have to do everything again.

Suggested solution

Implementing the swagger-features of prisma-class-generator in prisma-class-validator-generator

Additional context

As the current developer of the original prisma-class-generator does not seem to support the project further (no merge requests approved, etc...), I already forked it and did some fixes myself => published to @jannis6023/prisma-class-generator. The prisma-class-generator provides both the class generation process (just like yours) as well as optionally adding the swagger-decorators. One other immensively important feature is splitting relations into separate classes. Only in this way, we can use mapped types from nestjs (Intersecting base class with picked relation class).

I can't say how much work this would be to implement into your code, as I don't know your project very well. But I would be extremely happy to see this working! I can help you implementing this.

Best regards!

jannis6023 commented 1 week ago

I just tried to add class validator to my fork. It seems to work this way - but I guess you have much more expertise in class validator. May we communicate on where / in which way you iterate over the fields to infer the decorators?

Here is my try: https://github.com/jannis6023/prisma-class-generator/commit/bacad9c39af8ab0d65dd1758bb5a562daec74d21