-
Notifications
You must be signed in to change notification settings - Fork 844
It is not possible to automatically validate an empty object with forbidUnknownValues #1503
Description
Let's imagine that we are developing an application architecture on which application programmers will then layer business logic. We are currently creating a validation layer that will automatically validate incoming inputs from clients, simply by obtaining an input metatype that will be described by our future application programmer. Of course for these, we use class-validator library
According to the recommendation from the documentation(https://github.com/typestack/class-validator#passing-options), we use the setting forbidUnknownValues: true directly in the call to the validate method
But if in many months, our application developer decides to describe the following class for input:
export class EmptyObjectDto {}He will be very surprised, because the library will take a seemingly valid object for an invalid one, since there will not be a full registered decorator in it and it will give an error
Accordingly, he will not have any opportunity to give an empty input to our validation layer, and it will be necessary to add extra if->else from the area of responsibility to which he does not belong
Can we get around this somehow?