- Notifications
You must be signed in to change notification settings - Fork0
yantrab/class-validator-rule
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
It is possible to do strongly typed validation withclass-validator.
This class
enumColor{Red,Green,Blue}classSomeObject{string?:string;}classModel{color:Color;string:string;number:number;boolean:boolean;date:Date;stringArray:string[];numberArray:number[];booleanArray:boolean[];dateArray:Date[];enumArray:Color[];object:SomeObject;objectArray:SomeObject[];}
Should decorate like:
enumColor{Red,Green,Blue}classSomeObject{ @IsOptional() @IsString()string?:string;}classModel{ @IsEnum(Color)color:Color; @IsString()string:string; @IsNumber()number:number; @IsBoolean()boolean:boolean; @IsDate()date:Date; @IsString({each:true})stringArray:string[]; @IsNumber({},{each:true})numberArray:number[]; @IsBoolean({each:true})booleanArray:boolean[]; @IsDate({each:true})dateArray:Date[]; @IsEnum(Color,{each:true})enumArray:Color[]; @ValidateNested()object:SomeObject; @ValidateNested({each:true})objectArray:SomeObject[];}
This rule reminds you to add the correct decorator and can fix your models.
npm i tslint-class-validator-rule -DAdd tslint configoration to root of your models folder
{"rulesDirectory": ["tslint-class-validator-rule"],"rules": {"no-property-without-decorator":true }}Fix
tslint -p . --fixapp.useGlobalPipes(newValidationPipe({forbidUnknownValues:true}));
About
tslint rule for class-validator
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.