-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: forbid unknown values not working? #305
Comments
+1 Same behavior, using v0.9.1. Haven't tried with other versions. I also tried with the following ValidatorOptions, still the same, doesn't throw any validation errors.
|
I think what you want would be |
It doesn't seem to work with whitelist:true either (using NestJS). export class UpdateDto {
@MinLength(3)
@MaxLength(255)
readonly company: string;
@IsOptional()
@IsUUID('4')
readonly roleId: string;
}
//...
console.log(object);
const errors = await validate(object, { whitelist: true, forbidUnknownValues: true });
// console.log:
// UpdateDto {
// id: 'ed83f01a-9162-408b-9a6d-e0fd51f26284',
// roleId: '72ea4c50-f0c6-48d4-b3b6-318cc43448c3',
// company: 'Test',
// badkey: 1 } Note "id" and "badKey" is not defined in UpdateDto, errors are empty and the whole object is passed down to the controller with no stripping or finding errors. |
this config worked for me:
|
should exists an option like:
To remove any not allowed field/value, and not throw error. |
Having the same issue anyone share to shed some light on this ? :) |
@nigelthinksprint dunno, but same here too. |
Hi all, class-validator/test/functional/validator-options.spec.ts Lines 42 to 63 in 94e3ead
forbidUnknownValues will create validation error in case you pass instance of class not registered in class-validator metadata storage.
So you have to use We should update docs in this case and describe |
@vlapo thanks for the reply. My primary issue here is that the last time I checked, |
@rmainseas Did not test it on my environment but we have test with class-validator/test/functional/whitelist-validation.spec.ts Lines 26 to 47 in 94e3ead
|
@vlapo Hi. Any chance you guys update the naming (or add a bit detailed description) for |
This worked for me :) |
Closing this as solved. The related issue about renaming has been opened. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Good day.
I'm trying to deal with unknown values on a model, but it seems not working. What i'm doing wrong?
Output is empty array:
The text was updated successfully, but these errors were encountered: