### Install Prisma Class Validator Generator Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Installs the prisma-class-validator-generator package using npm, yarn, or pnpm. ```bash npm install prisma-class-validator-generator yarn add prisma-class-validator-generator pnpm add prisma-class-validator-generator ``` -------------------------------- ### Install Beta Version Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Installs the beta version of prisma-class-validator-generator, which includes support for Prisma 6.x and enhanced features. ```bash npm install prisma-class-validator-generator@beta ``` -------------------------------- ### Development Setup and Commands Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Instructions for setting up the development environment and common commands for building, testing, and formatting the project. These commands are crucial for developers contributing to or working with the generator. ```bash git clone https://github.com/omar-dulaimi/prisma-class-validator-generator.git cd prisma-class-validator-generator npm install npm run build npm test ``` ```bash npm run build # Compile TypeScript npm run start # Build and run Prisma generate npm test # Run tests in watch mode npm run test:ci # Run tests with coverage npm run format # Format code with Prettier ``` -------------------------------- ### Usage Example Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Demonstrates how to import and use the generated User model with class-validator for validation in a TypeScript application. ```typescript import { User } from './generated/models'; import { validate } from 'class-validator'; const user = new User(); user.id = 1; user.email = 'user@example.com'; user.name = 'John Doe'; const errors = await validate(user); if (errors.length > 0) { console.log('Validation failed:', errors); } else { console.log('User is valid!'); } ``` -------------------------------- ### Prisma Generator Configuration Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Example Prisma schema configuration for the class_validator generator. Specifies the provider, output directory, and options for Swagger decorators and separate relation fields. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./src/models" // Output directory swagger = "true" // Add Swagger decorators separateRelationFields = "true" // Split base/relation classes } ``` -------------------------------- ### Generated Enum Example Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Demonstrates the generation of a TypeScript enum from a Prisma schema enum definition. This example shows the 'Role' enum with its possible values. ```typescript export enum Role { USER = "USER", ADMIN = "ADMIN", MODERATOR = "MODERATOR", } ``` -------------------------------- ### User Model with Swagger Decorators Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Example of a generated User class incorporating NestJS Swagger decorators (`@ApiProperty`) alongside class-validator decorators, enabled by the `swagger = "true"` configuration option. ```typescript export class User { @IsDefined() @ApiProperty({ example: 'Generated by autoincrement', type: "integer" }) @IsInt() id!: number; @IsDefined() @ApiProperty({ type: "string" }) @IsString() email!: string; @IsOptional() @ApiProperty({ type: "string", required: false }) @IsString() name?: string | null; } ``` -------------------------------- ### Full NestJS Integration Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Combines Swagger support and relation splitting for a comprehensive setup ideal for NestJS applications, providing automatic Swagger docs and flexible DTOs. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" swagger = "true" separateRelationFields = "true" } ``` -------------------------------- ### Generated User Model with Class Validators Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Example of a generated TypeScript User model class. It utilizes decorators from 'class-validator' to define validation rules for each property, ensuring data integrity. Dependencies include 'class-validator' and custom enums/models. ```typescript import { IsString, IsDefined, IsEmail, IsOptional, IsEnum, IsDate } from "class-validator"; import { Role } from "../enums"; import { Profile } from "./Profile.model"; import { Post } from "./Post.model"; export class User { @IsDefined() @IsString() id!: string; @IsDefined() @IsEmail() email!: string; @IsOptional() @IsString() name?: string | null; @IsDefined() @IsEnum(Role) role!: Role; @IsOptional() profile?: Profile | null; @IsDefined() posts!: Post[]; @IsDefined() @IsDate() createdAt!: Date; @IsDefined() @IsDate() updatedAt!: Date; } ``` -------------------------------- ### Common Development Commands Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Provides essential commands for building, testing, formatting, and publishing the Prisma Class Validator Generator. These commands streamline the development workflow. ```bash npm run build npm run start npx prisma generate npm test npm run test:ci npm run test:coverage npm run test:type-check npm run format npm run format:check npm run package:publish ``` -------------------------------- ### Testing Commands Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Commands to run tests for the generator. Includes options for running tests in watch mode, running tests once with coverage, and generating a coverage report. These commands are essential for verifying the generator's functionality and ensuring code quality. ```bash npm test # Run tests in watch mode npm run test:ci # Run tests once with coverage npm run test:coverage # Generate coverage report ``` -------------------------------- ### Testing Generator Locally Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Instructions for testing the Prisma generator locally using specific schema files. This allows for verification of generated models in a controlled environment. ```bash npx prisma generate --schema=tests/schemas/basic.prisma ``` -------------------------------- ### Generated File Structure Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Illustrates the typical directory structure of files generated by the 'prisma-class-validator-generator'. It organizes generated models, enums, and index files into dedicated directories, promoting a clean project structure. ```bash generated/ ├── models/ │ ├── User.model.ts │ ├── Post.model.ts │ └── index.ts ├── enums/ │ ├── Role.ts │ └── index.ts └── index.ts ``` -------------------------------- ### Prisma Generator Configuration Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Configuration block for the 'prisma-class-validator-generator' within the 'schema.prisma' file. Specifies the provider and an optional output directory for the generated files. This is the primary way to integrate the generator into a Prisma project. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" # Optional: output directory } ``` -------------------------------- ### Prisma Generator Configuration Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Demonstrates how to configure the 'prisma-class-validator-generator' within a Prisma schema file. It includes optional parameters for output directory, Swagger integration, and relation field separation. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" // optional, defaults to ./generated swagger = "true" // optional, adds @ApiProperty decorators separateRelationFields = "true" // optional, creates separate base/relation classes } ``` -------------------------------- ### Generate Models Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Executes the Prisma generate command to create the TypeScript models based on the Prisma schema and the configured generator. ```bash npx prisma generate ``` -------------------------------- ### Swagger Support Output Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md The generated TypeScript code includes @ApiProperty decorators for Swagger documentation, alongside the class-validator decorators. ```typescript export class User { @IsDefined() @ApiProperty({ example: 'Generated by autoincrement', type: "integer" }) @IsInt() id!: number; @IsDefined() @ApiProperty({ type: "string" }) @IsString() email!: string; } ``` -------------------------------- ### Prisma Schema Configuration Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Adds the prisma-class-validator-generator as a generator in your Prisma schema file. This tells Prisma to use the generator to create models. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" // optional, defaults to ./generated } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt title String content String? published Boolean @default(false) viewCount Int @default(0) author User? @relation(fields: [authorId], references: [id]) authorId Int? rating Float } ``` -------------------------------- ### Enabling Debug Mode Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Command to enable debug logging for the Prisma generator. By setting the DEBUG environment variable, you can capture detailed logs that are helpful for troubleshooting issues related to the generator's execution. ```bash DEBUG=prisma:generator npx prisma generate ``` -------------------------------- ### Basic Usage Output Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md The resulting TypeScript code generated by the basic configuration, featuring classes with validation decorators like @IsDefined(), @IsInt(), and @IsString(). ```typescript export class User { @IsDefined() @IsInt() id!: number; @IsDefined() @IsString() email!: string; } ``` -------------------------------- ### User Model Generation Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Generates a TypeScript User class with class-validator decorators based on the Prisma schema. Includes basic validation for ID, email, name, and posts. ```typescript import { IsInt, IsDefined, IsString, IsOptional } from "class-validator"; import { Post } from "./Post.model"; export class User { @IsDefined() @IsInt() id!: number; @IsDefined() @IsString() email!: string; @IsOptional() @IsString() name?: string | null; @IsDefined() posts!: Post[]; } ``` -------------------------------- ### Configuration Flags Explained Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Details the optional configuration flags for the Prisma Class Validator Generator: `swagger` and `separateRelationFields`. These flags customize the generated TypeScript models for specific use cases like NestJS API documentation and DTO management. ```APIDOC Configuration Flags: swagger (optional, default: false) Description: Adds NestJS Swagger @ApiProperty decorators alongside class-validator decorators. Includes type information, examples, array handling, and enum values. Useful for automatic API documentation generation in NestJS applications. separateRelationFields (optional, default: false) Description: Splits models into separate base and relation classes for better NestJS integration. Creates `ModelBase` (scalar fields only), `ModelRelations` (relations only), and combined `Model` class. Enables use of NestJS mapped types like `PickType`, `PartialType`, etc. Perfect for DTOs that need to exclude relations or work with specific field subsets. ``` -------------------------------- ### Basic Usage Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Generates TypeScript classes with class-validator decorators from a Prisma schema. This is the fundamental configuration for the generator. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" } ``` -------------------------------- ### Post Model Generation Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/README.md Generates a TypeScript Post class with class-validator decorators. Includes validation for ID, dates, title, content, published status, view count, author, author ID, and rating. ```typescript import { IsInt, IsDefined, IsDate, IsString, IsOptional, IsBoolean, IsNumber } from "class-validator"; import { User } from "./User.model"; export class Post { @IsDefined() @IsInt() id!: number; @IsDefined() @IsDate() createdAt!: Date; @IsDefined() @IsDate() updatedAt!: Date; @IsDefined() @IsString() title!: string; @IsOptional() @IsString() content?: string | null; @IsDefined() @IsBoolean() published!: boolean; @IsDefined() @IsInt() viewCount!: number; @IsOptional() author?: User | null; @IsOptional() @IsInt() authorId?: number | null; @IsDefined() @IsNumber() rating!: number; } ``` -------------------------------- ### Swagger Support Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Enables Swagger documentation decorators (@ApiProperty) in the generated TypeScript classes. This is useful for API development with tools like NestJS. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" swagger = "true" } ``` -------------------------------- ### Relation Splitting Source: https://github.com/omar-dulaimi/prisma-class-validator-generator/blob/master/CLAUDE.md Configures the generator to separate scalar and relation fields into different files. This promotes better organization for complex models. ```prisma generator class_validator { provider = "prisma-class-validator-generator" output = "./generated" separateRelationFields = "true" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.