metaschema icon indicating copy to clipboard operation
metaschema copied to clipboard

Partial schema validation

Open lundibundi opened this issue 2 years ago • 7 comments

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.

lundibundi avatar May 11 '22 19:05 lundibundi

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 avatar May 21 '22 21:05 georgolden

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

georgolden avatar Jun 10 '22 05:06 georgolden

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.

lundibundi avatar Jun 14 '22 14:06 lundibundi

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 avatar Jul 20 '22 16:07 georgolden

Schema.partialCheck similar to existing Schema.check

georgolden avatar Jul 20 '22 16:07 georgolden

I can take this issue

Bespaliy avatar Jul 21 '22 08:07 Bespaliy

@Bespaliy then take it please

georgolden avatar Jul 26 '22 15:07 georgolden