ValidateNested not working
See original GitHub issueHello,
i have something like this:
class Day
{
@IsMilitaryTime()
from: string;
@IsMilitaryTime()
to: string;
}
export class DailyCalendar
{
@IsDefined() // do i need it?
@ValidateNested()
monday: Day;
...
}
When calling the route with this body: { "monday": { "from": "foo" } } or { "monday": { } } it doesn’t throw an error.
Also when not using @IsDefined() i can call the route without monday property and it doesn’t throw an error.
The class will be created, but not validated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (9 by maintainers)
Top Results From Across the Web
Validate nested objects using class validator and nestjs
I've just put your code in an empty sample project and it seems to work for me. What specific value is "not working"?...
Read more >Validating nested objects with class-validator in NestJS
import { ValidateNested } from 'class-validator'; export class Post ... i could solve this problem with the help of custom recursive ...
Read more >typestack/class-validator - Gitter
Hello - I'm using class-validator within NestJS and liking it! - but I'm struggling with the @IsMobilePhone() decorator - it isn't respecting the...
Read more >How to use the class-validator.IsIn function in class-validator
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >class-validator - npm
Start using class-validator in your project by running `npm i ... otherwise @ValidateNested won't know what class is target of validation.
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

Well, I’ve just solved my problem, I share the solution:
DummyDto (main class)
SubDto file:
This dto works:
This dto fails:
Note for NestJs users:
The ValidatorPipe is very similar to the existing on docs.
I hope this helps somebody.
I have the same problem. This work for me:
@Typeis from module class-transformer.