【问题标题】:NestJs - ParseUUIDPipe - Validation failed (uuid vundefined is expected)NestJs - ParseUUIDPipe - 验证失败(预期为 uuid vundefined)
【发布时间】:2020-04-11 16:57:42
【问题描述】:

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

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

我收到以下错误:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Validation failed (uuid vundefined is expected)"
}

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

【问题讨论】:

    标签: nestjs


    【解决方案1】:

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

    new ParseUUIDPipe({version: '4'})
    

    【讨论】:

    • 你能接受你自己的答案吗?如果可以的话? :)
    • 只是对此的更新 - 显然不再需要该版本,@Param('id', ParseUUIDPipe) id: string 应该可以工作
    猜你喜欢
    • 2018-11-02
    • 2022-01-09
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2011-02-03
    • 2021-12-17
    相关资源
    最近更新 更多