metaschema
metaschema copied to clipboard
Partial schema validation
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.
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.
@lundibundi I see two solutions here. 1st - use projection. 2nd - make additional method, which checks only given fields if it is in schema
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.
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' }
Schema.partialCheck
similar to existing Schema.check
I can take this issue
@Bespaliy then take it please