比如我有个参数叫 classType , 是字符串数组,值只能是 "a" 或者 "b", 也可以同时两个,所以希望设置输入参数的时候只能是这3个 ["a"] ["b"] ["a","b"] ,这个在 class-validator 要如何设置? @IsArray() // @IsEnum(['a', 'b']) 我一开始是这样设置的,但是不行,只 classType = ["a"]...
validationOptions?:ValidationOptions){returnfunction(object:Object,propertyName:string){registerDecorator({name:'isLongerThan',target:object.constructor,propertyName:propertyName,constraints:[property],options:validationOptions,validator:{validate(value:any,args:ValidationArguments)...
这里贴下主页的源码,实际使用就是照葫芦画瓢就可以了。 import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'; export function IsLongerThan(property: string, validationOptions?: ValidationOptions) { return function (object: Object, propertyName: string) { registerDecor...
@IsIn(values: any[]) Checks if value is in a array of allowed values. 检查值是否在允许值的数组中 @IsNotIn(values: any[]) Checks if value is not in a array of disallowed values. 检查值是否不在不允许的值数组中 类型验证装饰器 修饰器描述(英文)描述(中文) @IsBoolean() Checks if a va...
首先,确保你已经在项目中安装了class-validator和class-transformer库。你可以使用以下命令进行安装: 代码语言:txt 复制 npm install class-validator class-transformer 创建一个DTO(数据传输对象)来定义你的嵌套对象。在DTO中,你可以使用@ValidateNested()和@Type()装饰器来指定验证规则。例如: ...
export interface ValidatorOptions { skipMissingProperties?: boolean; whitelist?: boolean; forbidNonWhitelisted?: boolean; groups?: string[]; dismissDefaultMessages?: boolean; validationError?: { target?: boolean; value?: boolean; }; forbidUnknownValues?: boolean; stopAtFirstError?: boolean; }...
nestclass-validator验证修饰器中文文档 nestclass-validator验证修饰器中⽂⽂档 验证修饰器 通⽤验证 修饰器描述(英⽂)描述(中⽂)@IsDefined(value: any)Checks if value is defined (!== undefined, !== null). This is the only decorator that ignores skipMissingProperties option.检查是否定义了...
import { validate, validateOrReject, Contains, IsInt, Length, IsEmail, IsFQDN, IsDate, Min, Max, } from 'class-validator'; export class Post { @Length(10, 20) title: string; @Contains('hello') text: string; @IsInt() @Min(0) @Max(10) rating: number; @IsEmail() email: string...
class-validator#IsArrayTypeScript Examples Example #1 Source File:shared.dto.tsFrom affinidi-core-sdk with Apache License 2.06votes @IsArray()@IsIn(['rsa','bbs','ecdsa'], { each:true}) keyTypes: KeyAlgorithmType[] Example #2 Source File:classes.tsFrom epicgames-freegames-node with MIT ...
export interface ValidatorOptions { skipMissingProperties?: boolean; whitelist?: boolean; forbidNonWhitelisted?: boolean; groups?: string[]; dismissDefaultMessages?: boolean; validationError?: { target?: boolean; value?: boolean; }; forbidUnknownValues?: boolean; stopAtFirstError?: boolean; }...