Nest: ValidationPipe does not specify property name when ValidateNested is used with custom type array

Created on 3 Sep 2020  路  5Comments  路  Source: nestjs/nest

Feature Request

Is your feature request related to a problem? Please describe.

Given a DTO with a following property definition:

class Dto {
  @Expose()
  @IsDefined()
  @ValidateNested({ each: true })
  @Type((unit) => CustomType)
  props: CustomType[]
}

and CustomType e.g.

export class CustomType {
  @Expose()
  @IsString()
  @IsUUID()
  id: string
}

an input object:

{
  "props": []
}

will yield such an error from ValidationPipe:

{
    "statusCode": 400,
    "message": [
        "0.id must be an UUID",
        "0.id must be a string",
    ],
    "error": "Bad Request"
}

It is not clear at the moment which property is triggering a validation error (in case of many array type properties).

Describe the solution you'd like

I'd go with something like:

{
    "statusCode": 400,
    "message": [
        "props.0.id must be an UUID",
        "props.0.id must be a string",
    ],
    "error": "Bad Request"
}
needs triage type

Most helpful comment

@jmcdo29 @pbn4 I would like to work on a PR if that is okay.

All 5 comments

Looks like it will be related to this. Would you like to work on a PR?

@jmcdo29 @pbn4 I would like to work on a PR if that is okay.

Thanks for reporting! PRs are more than welcome @princechauhan1992 @pbn4 :)

Ping @princechauhan1992 馃彄

@kamilmysliwiec I apologize for the delay. Will create a pr this weekend.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VRspace4 picture VRspace4  路  3Comments

thohoh picture thohoh  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

hackboy picture hackboy  路  3Comments

mishelashala picture mishelashala  路  3Comments