question: ValidateNested with IsOptional throws a BadRequest
See original GitHub issueCurrently using -
- class-transformer - 0.2.3
- class-validator - 0.11.0
- express - 4.15.4
- node version - 13.9.0
I have 2 classes -
export class A {
@IsNotEmpty()
@Length(2, 32)
public someField: string;
@IsOptional()
@IsEnum(EnumClass)
public someEnum: EnumClass;
}
export class B {
@ValidateNested({ each: true })
@Type(() => A)
public arrayOfAs: A[];
}
For some reason - I get a BadRequest when I don’t send the enum type although it’s decorated with “IsOptional”, am I doing something wrong or is that a bug? Couldn’t find any sample of code to validate a nested object array with isOptional decoraror.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
IsDefined + IsOptional combination return error 500 instead of ...
Should return error 400 bad request, since its undefined. Actual behavior. It throws internal server error (isnt returning the error 400).
Read more >Validating nested objects with class-validator in NestJS
Today I have for you a quick and short article. Maybe it will help someone. I'm using class-validator for request validation in NestJS ......
Read more >mongodb - Validate nested object with dot syntax using class ...
I'm having trouble on validating nested object when I try to update a specific prop of a nested object e.g.:
Read more >Validation | NestJS - A progressive Node.js framework
By default it throws BadRequestException . exceptionFactory, Function, Takes an array of the validation errors and returns an exception object to be thrown....
Read more >class-validator - Bountysource
I understand that this problem is concerning class-transformer more than it is ... import { IsString, ValidateNested, validateSync } from 'class-validator'; ...
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
Hi @vlapo, Not really, but after a clean build + set and unset of defaultErrorHandler on routing-controller options I got data on the “errors” property of the error object, not sure why (as per the documentation of routing controllers defaultErrorHandler is set by default on dev environment, but explicitly setting it to true building and then back to false then a rebuild solved the problem) might have been a cache problem? 0_o
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.