Custom Validator Whitelisting

[Solved] Custom Validator Whitelisting | Solidity - Code Explorer | yomemimo.com
Question : custom validator Whitelisting

Answered by : barisx

/*
* Even if your object is an instance of a validation class
* it can contain additional properties that are not defined.
* If you do not want to have such properties on your object,
* pass special flag to validate method:
*/
import {validate, Allow, Min} from "class-validator";
export class Post { @Allow() title: string; @Min(0) views: number; nonWhitelistedProperty: number;
}
let post = new Post();
post.title = 'Hello world!';
post.views = 420;
post.nonWhitelistedProperty = 69;
(post as any).anotherNonWhitelistedProperty = "something";
validate(post).then(errors => { // post.nonWhitelistedProperty is not defined // (post as any).anotherNonWhitelistedProperty is not defined ...
});

Source : https://github.com/typestack/class-validator/blob/develop/README.md#validating-arrays | Last Update : Thu, 07 Apr 22

Answers related to custom validator whitelisting

Code Explorer Popular Question For Solidity