Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial schema validation #394

Open
lundibundi opened this issue May 11, 2022 · 7 comments
Open

Partial schema validation #394

lundibundi opened this issue May 11, 2022 · 7 comments
Assignees

Comments

@lundibundi
Copy link
Member

Is your feature request related to a problem? Please describe.
Sometimes it is necessary to support update-like methods and currently it is not possible to perform Schema#check on partial objects.

Describe the solution you'd like
It would be good to have an ability to check patches\updates using general Schema. Via separate method or custom options to check that would disable required checks and some other while still having an ability to check fields.

@georgolden
Copy link
Member

So common practice is to use DTO, we can handle such a functionality using Projection. I am not sure, that it is a good idea, to keep delta objects validated with schema. I suggest to use Projection as a DTO for validating update deltas or same cases.

@georgolden
Copy link
Member

@lundibundi I see two solutions here. 1st - use projection. 2nd - make additional method, which checks only given fields if it is in schema

@lundibundi
Copy link
Member Author

Additional method would be better because IMO projection is for more "stable" things and creating one each time we want to vaildate some fields would be wasteful.

@georgolden
Copy link
Member

To-Do

  • add method to schema for partial validation
    Test:
    Schema:
({
  Entity: {},

  login: { type: 'string', length: { min: 8, max: 64 }, unique: true },
  password: { type: 'string', note: 'Password hash' },
  roles: { many: 'Role' },
});

Object that contains at least 1 field from schema must be partially validated
{ password: 'asdja@LKJSD' }

@georgolden
Copy link
Member

Schema.partialCheck similar to existing Schema.check

@Bespaliy
Copy link
Member

I can take this issue

@georgolden
Copy link
Member

@Bespaliy then take it please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants