1

我有这堂课:

class SomeDto {
  @ArrayMaxSize(100)
  @Type(() => NestedDto)
  @ValidateNested({ each: true })
  nested: NestedDto[];
}

我使用验证管道作为:

@Body(new ValidationPipe({ transform: true })) { nested }: NestedDto,

它正确地进行了验证,但我每次都得到一个空的错误数组。

{
    "statusCode": 400,
    "message": "Bad Request",
    "error": []
}
4

1 回答 1

0

首先 - 请分享NestedDto以了解其验证器。

其次,我认为问题在于您使用NestedDto而不是SomeDto在体内。

@Body(new ValidationPipe({ transform: true })) { nested }: SomeDto // <- Not NestedDto.

在这种情况下,我得到了关于数组大小的正确错误。

于 2020-05-16T16:47:02.457 回答