Nest: ValidateNested does not work

Created on 19 Feb 2018  路  5Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When using ValidateNested from class-validator to validate a nested object on a dto, the validation passes successfully with invalid nested objects.

Expected behavior

When using ValidateNested to validate a nested object on a dto, the validation should fail with validation rules.

Minimal reproduction of the problem with instructions


https://gist.github.com/chimon2000/d2203b281bbaea570eeccb36ebd6de9b

What is the motivation / use case for changing the behavior?

N/A

Environment


Nest version: 4.6.4

For Tooling issues:

  • Node version: v8.9.4
  • Platform: Windows

Others:
N/A

Most helpful comment

@ValidateNested()
@Type(() => AddressDto) // add this from class-transformer
readonly address: AddressDto

All 5 comments

@ValidateNested()
@Type(() => AddressDto) // add this from class-transformer
readonly address: AddressDto

That resolved my issue. Thanks!

Is it possible to reopen this issue? I'm currently experiencing this, and unfortunately @chanlito's solution doesn't do the trick.

If @chanlito solution does not work try using @IsNotEmpty() to the parent property, like this:

@IsNotEmpty() delivery: Delivery;

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cojack picture cojack  路  3Comments

cdiaz picture cdiaz  路  3Comments

anyx picture anyx  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

tronginc picture tronginc  路  3Comments