NestJs - ParseUUIDPipe - 验证失败(需要 uuid vundefined)

col*_*r-j 1 nestjs

我有一个基本的控制器设置:

@Controller('')
export class AController {
 @Get(':id')
  async getThing(@Param('id', ParseUUIDPipe) id: string): Promise<RegisterRead[] | IntervalRead[]> {
      return id
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Validation failed (uuid vundefined is expected)"
}
Run Code Online (Sandbox Code Playgroud)

另见:https : //github.com/nestjs/nest/issues/2960

col*_*r-j 5

这个问题是因为我没有指定版本。它将版本显示为可选字段,但似乎是必需的:

new ParseUUIDPipe({version: '4'})
Run Code Online (Sandbox Code Playgroud)

  • 只是对此进行更新 - 显然不再需要该版本,并且 `@Param('id', ParseUUIDPipe) id: string` 应该可以工作 (3认同)