【发布时间】:2022-01-05 05:34:24
【问题描述】:
我想知道是否有办法创建一个 dto 来验证对象数组?
示例数组:
[
{
"name": "Tag 1",
"description": "This is the first tag"
},
{
"name": "Tag 2",
"description": "This is the second tag"
}
]
目前我有这个,虽然它有效,但它不是我所追求的。
export class Tags {
@ApiProperty({
description: 'The name of the tag',
example: 'Tag 1',
required: true
})
@IsString()
@MaxLength(30)
@MinLength(1)
name: string;
@ApiProperty({
description: 'The description of the tag',
example: 'This is the first tag',
required: true
})
@IsString()
@MinLength(3)
description: string;
}
export class CreateTagDto {
@ApiProperty({ type: [Tags] })
@Type(() => Tags)
@ArrayMinSize(1)
@ValidateNested({ each: true })
tags: Tags[];
}
【问题讨论】:
-
您只想发送数组而不是带有标签键的对象?
-
@LarsFlieger 是正确的。
标签: javascript express nestjs swagger-ui class-validator