No metadata found for class-validator
This is because you are using class-validator
but without any validations, see this issue:
Basically, it warns that you don't have any metadatas in the storage, which means you haven't used any decorator from class-validator. That means you don't perform any validation, so you should just pass
validate: false
option tobuildSchema
to disable automatic validation.
I'm not sure if you can turn of validation for nest's ValidationPipe
, but alternatively you can just add an assertion to your dto (if it makes sense), e.g.:
import { Min } from 'class-validator';
export class QueryDto {
@Min(1)
readonly limit: number = 50;
}
By the way: Since your @Query
will only have string properties, you'll probably want to transform your limit
from string
to number
. Have a look at this answer.
The question has already been answered, but for future reference of people with the same problem...
The class-validator allows you to bypass the validation of certain property (whitelisting) special flags to validate any property.
As the docs:
This will strip all properties that don't have any decorators. If no other decorator is suitable for your property, you can use @Allow decorator
e.g:
import {validate, Allow, Min} from "class-validator";
export class Post {
@Allow()
title: string;
@Min(0)
views: number;
nonWhitelistedProperty: number;
}