I’m using the class-validator npm package and would like to validate that the type property of request body matches one either ‘organization’ or ‘student’. How would I do this with this package? This doesn’t work: Request body example: Answer You can use something like this in your model class. Instead of @IsIn use enum.
Tag: class-validator
Validate array object – Swagger/NestJS
I am wondering if there’s a way to create a dto to validate array of object? Example array: At the moment I have this, while it works, it isn’t what I am after. Answer Just use ParseArrayPipe: Update your Controller: Ensure to have items and whitelist set. Update your DTO:
Validate nested objects using class validator and nestjs
I’m trying to validate nested objects using class-validator and NestJS. I’ve already tried following this thread by using the @Type decorator from class-transform and didn’t have any luck. This what I have: DTO: I’m also using built-in nestjs validation pipe, this is my bootstrap: It’s working fine for other properties, the array of objects is the only one not working.