这工作正常:
import { IsIn } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class createEventDto {
@IsIn([0, 1, 2, 3, 4, 5])
@ApiProperty({
description: 'description of the severity property',
})
severity: number;
}
我试图了解如何将严重性类型更改为枚举,我尝试过什么:
export enum Severity {
Critical = 1,
Major = 2,
Minor = 3,
Warning = 2,
Info = 1,
Clear = 0,
}
import { IsEnum } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Severity} from '../enums/severities';
export class createEventDto {
@IsEnum(Severity)
@ApiProperty({
description: 'description of the severity property',
})
severity: Severity;
}