ValidationPipe does not specify property name when ValidateNested is used with custom type array
See original GitHub issueFeature 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:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jmcdo29 @pbn4 I would like to work on a PR if that is okay.
@kamilmysliwiec I apologize for the delay. Will create a pr this weekend.