Open RRGT19 opened 3 years ago
Any updates on this? I'm facing the same issue.
same
Due to the nature of Typescript decorators, All of the decorators are going to run in reversed order as for: https://www.typescriptlang.org/docs/handbook/decorators.html#decorator-composition
Therefore, it's not really related to your custom rule as you probably thought. Since your custom decorator is the last decorator, it means that it's going to be the first decorator to be executed. That's why you are seeing its error message.
Due to the nature of Typescript decorators, All of the decorators (...)
This is correct, but it will not work in the way you describe (reversed from decoration) with async validators. Async validation will be triggered at the beginning. I described it better under: https://github.com/typestack/class-validator/issues/1688 I would propose to close this ticket and keep only #1688 since stopAtFirstError option has nothing to do with the origin of the problem.
@smentek @RRGT19 @secmohammed @thiennhan2310 @feRpicoral Can any of you help me understand y this one passes when I send a req without this optional param (someString
) ?
If it runs in the reversed order so I would expect it to fail on the IsNotEmpty
decorator.
export class SomeDto {
@IsOptional()
@IsString()
@IsNotEmpty()
public someString?: string
.
.
.
}
Thanks a lot ! 🙏
Is stopAtFirstError really working for someone, I am trying to configure it as below and its not working at all. Is there something I am missing in configuration.
app.useGlobalPipes( new ValidationPipe({ transform: true, stopAtFirstError: true, }), );
i am facing the same issue
+1
Is stopAtFirstError really working for someone, I am trying to configure it as below and its not working at all. Is there something I am missing in configuration.
app.useGlobalPipes( new ValidationPipe({ transform: true, stopAtFirstError: true, }), );
I am facing the same issue. Even after enabling the option nothing seems to change and class-validator generates too many errors as before.
Is this active?
I'm facing the same issue and is a bit concerning since this feature is quite necessary to prevent from potential ReDoS attacks (if a long string is catched earlier with @Max()
then there's no need for the @Matches()
validator to be executed).
Anyone has solution for this issue?
Description
I have a custom decorator as the last one that validates a string against my database. It's still being called and executed even if a previous validator has failed.
ValidationPipe configuration
Entity DTO
POST Request example
Response
My custom validator and decorator
Expected behavior
Just the result of a previous validation, example:
To be more precise, the
@IsNotEmpty()
should have stop the empty string as shown above, being the only error returned to the client.Actual behavior
The custom validator, which is the last one, is still being called and executed.
class-validator: 0.13.1