Skip to content

question: How to get object state before it was transformed in Validator? #2455

Open
@rantiev

Description

@rantiev

Sometimes due to wrong object scheme we get undefined values as a result of transformation. Hence if you use IsOptional flag, you can't check was this field transformed wrong or it didn't exist in original object.

Hence there is no difference for IsOptional fields validation of undefined fields. They just skipped.

In my opinion IsOptional should skip values only if they were missing in original object. If they were transformed wrong we need to think that they didn't pass validation. (if they transformed wrong we got wrong object input - validation should fail as it checks scheme, even if transformed scheme)

I want to create my own @WasTransformedProperly() or @IsOptionaIfNotSetOriginally()
Or to check original object state in my custom validators...

Is this possible?

I see that other people are complaining about similar cases (IsOptional skipping undefined when it shouldn't) also.
What could we do with this? Any workaround, proposal or existing PRs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions