The `prisma-class-validator-generator` is a utility that automates the creation of TypeScript data transfer objects (DTOs) directly from a Prisma schema, automatically decorating them with `class-validator` rules. This eliminates significant boilerplate for developers working with Prisma and `class-validator` for input validation. The package is currently stable at version `6.2.0`, following a relatively active release cadence with semantic versioning adopted since v6.1.0, indicating consistent development and maintenance. Key differentiators include its tight integration with Prisma, providing automatic mapping of Prisma types to appropriate validation decorators, ensuring type-safety, and offering a zero-configuration setup for immediate use. It supports modern Prisma versions, currently `Prisma 6.12+`, and is designed for Node.js 18+ environments with TypeScript 5.8+. This generator is crucial for projects aiming for robust backend validation without manually synchronizing schema changes with validation classes.
npm install prisma-class-validator-generatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure the `prisma-class-validator-generator` in your Prisma schema, generate the TypeScript models, and then use `class-validator` along with `class-transformer` to validate data against the generated `User` class.
Migrate any custom logic or validations related to Prisma `Bytes` fields to use `Uint8Array` instead of Node.js `Buffer` instances.
Upgrade your `prisma` and `@prisma/client` packages to version 5.x or newer and run `npx prisma generate`. Review Prisma's official migration guides for specific changes.
Ensure your `schema.prisma` file includes a `generator client` block, e.g., `generator client { provider = "prisma-client" output = "../generated/prisma-client" }`.Upgrade your Node.js environment to version 18.18+, 20.9+, or 22.11+ and your TypeScript dependency to 5.8+.
Run `npm install prisma-class-validator-generator` or `yarn add prisma-class-validator-generator` in your project.
Ensure you've run `npx prisma generate` successfully. Verify the `output` path in your `schema.prisma` generator configuration matches your import path, and check if the files were indeed created at the specified location.
Use `class-transformer`'s `plainToClass` function to convert your plain object into an instance of the generated class before calling `validate()`. Example: `const instance = plainToClass(MyGeneratedClass, plainObject); await validate(instance);`