-
Notifications
You must be signed in to change notification settings - Fork 845
Description
Description
有时验证一个对象时我并不希望验证所有的属性,并且通过重写基类减少子类属性是不可取的,因为某些属性验证时依赖其他属性值,我尝试了很多办法,都没能解决我的问题,希望增加一个能缩小验证属性范围的选项、功能
Machine translation:
At times, when validating an object, I do not wish to validate all its properties. Moreover, reducing subclass properties by overriding the base class is undesirable, as certain property validations depend on the values of other properties. I have tried numerous approaches, yet none have resolved my issue. I would like to see an option or feature introduced that allows narrowing the scope of validated properties.
Proposed solution
我能想到的办法是按分组验证时,增加一个选项以支持验证分组的交集(目前分组验证的策略是验证所有包含在这些分组的所有属性,也就是并集)
Machine translation:
The solution I can conceive is to add an option during grouped validation to support verifying the intersection of groups (the current validation strategy for grouped attributes is to verify all attributes contained within these groups, i.e. the union).
就像这样(exp):
class Validator {
@Xxx({
groups: ['A'],
})
aaa: any;
@Xxx({
groups: ['B', 'X'],
})
bbb: any;
@Xxx({
groups: ['C', 'X'],
})
ccc: any;
}
validate(new Validator(), {
groups: ['A'],
});
// validate prop: aaa
validate(new Validator(), {
groups: ['B', 'X'],
});
// validate prop: bbb,ccc
validate(new Validator(), {
groups: ['B', 'X'],
groupMode: 'union'
});
// validate prop: bbb