I was trying to...
I'm trying to validate an object type using NestJS / class-validator (v0.13.2) like this.
@ValidateIf(o => o.someProp === false)
@IsOptional()
@Validate(SomeCustomValidator)
@ValidateNested()
@Type(() => SomeDto)
prop?: SomeDto
My validator config:
{
validateCustomDecorators: true,
stopAtFirstError: true,
always: false
}
The problem:
The custom validator gets executed every time, even if input is invalid, so @ValidateNested should catch it and prevent further validation for this property. As far as I know validators are executed in a bottom-to-top order.
If remove the custom validator, I get a proper validation error, but if it's there, I get 500 because it tries to run using the invalid input.
How can I fix this? I want the validation to stop if input data is invalid. The custom validator should only run with valid input.
Btw: is there a way to halt validation globally (not only for the given prop) as soon as some validator fails?
I was trying to...
I'm trying to validate an object type using NestJS / class-validator (v0.13.2) like this.
My validator config:
The problem:
The custom validator gets executed every time, even if input is invalid, so @ValidateNested should catch it and prevent further validation for this property. As far as I know validators are executed in a bottom-to-top order.
If remove the custom validator, I get a proper validation error, but if it's there, I get 500 because it tries to run using the invalid input.
How can I fix this? I want the validation to stop if input data is invalid. The custom validator should only run with valid input.
Btw: is there a way to halt validation globally (not only for the given prop) as soon as some validator fails?