Add support for validating an empty class with forbidUnknownValues
enabled
#1782
Replies: 2 comments 3 replies
-
Yes, this use case should be supported. The technical problem here is that without decorators assigned We need to discuss how should we add support for this. My first (so probably not the best) idea would be to add a class decorator something like @ValidatedClass()
export class EmptyObjectDto {} This way PS: I am moving this issue to discussions, so the community can brainstorm, iterate and propose an API that we can discuss. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement class-level validation, but there's a lot of stuff to do before it can be done. I'll leave here a checklist to keep you guys updated, and tell me if I'm using the wrong branch (
I don't have much time now, but I'll be back to the required updates asp |
Beta Was this translation helpful? Give feedback.
-
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 methodBut if in many months, our application developer decides to describe the following class for input:
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?
Beta Was this translation helpful? Give feedback.
All reactions