Closed stefanoborini closed 1 year ago
Moreover, how can one set it globally for all validations?
Hi @stefanoborini
Your second example is the correct one:
public async create_product(@Body(ValidationPipe({ forbidNonWhitelisted: true, forbidUnknownValues: true })) body: CreateProductInput) {
The fact that it doesn't work is most probably not related to next-api-decorators
but how you construct your class and how you configure class-validator
and/or class-transformer
.
If you are sure the problem is related to next-api-decorators
, please provide a minimum reproducible repo and feel free to reopen the issue.
Moreover, how can one set it globally for all validations?
Unfortunately it's not possible to set validation options globally, as Next.js handles the routing. Your safest bet would be assigning the options to a global variable and pass it to each ValidationPipe
instance.
From the documentation, it's unclear how you are supposed to pass validation pipe configuration options. I am trying to prevent the received document to pass validation when it contains keys that I don't expect. Example
The above code does not work:
error - ReferenceError: options is not defined
.I also tried without new, with no result:
The type hinting seems to say I should pass the options at construction: