question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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"
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
princechauhan1992commented, Sep 5, 2020

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

0reactions
princechauhan1992commented, Nov 18, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

validate nested objects using class-validator in nest.js controller
Try specifying the nested type with @Type : import { Type } from 'class-transformer'; export class CurrencyDTO { @ValidateNested({ each: ...
Read more >
Validating nested objects with class-validator in NestJS
import { ValidateNested } from 'class-validator'; export class ... But if an object in the array doesn't pass validation, I receive only
Read more >
Validation | NestJS - A progressive Node.js framework
This setting allows you to specify which exception type will be used in case of an error. By default it throws BadRequestException ....
Read more >
NestJs Data Validation with ValidationPipe - YouTube
This video is part of the NestJs In Practice Course - https://angular-university.io/course/nestjs-courseCheck out the Angular University ...
Read more >
Use of DTO for Validation in NestJS Application - LinkedIn
DTO is the short name of Data Transfer Object. ... kind of shape the request body expects to be, it doesn't actually run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found