fix: support property dependecies with ownProperties option, #197
parent
df6ef691ae
commit
1babc9df49
|
@ -26,6 +26,9 @@ var missing{{=$lvl}};
|
|||
{{ $deps = $propertyDeps[$property]; }}
|
||||
{{? $deps.length }}
|
||||
if ({{=$data}}{{= it.util.getProperty($property) }} !== undefined
|
||||
{{? $ownProperties }}
|
||||
&& Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($property)}}')
|
||||
{{?}}
|
||||
{{? $breakOnError }}
|
||||
&& ({{# def.checkMissingProperty:$deps }})) {
|
||||
{{# def.errorMissingProperty:'dependencies' }}
|
||||
|
|
|
@ -141,6 +141,23 @@ describe('Ajv Options', function () {
|
|||
test(schema, obj, proto, 1, true);
|
||||
});
|
||||
|
||||
it('should only validate own properties with dependencies keyword', function() {
|
||||
var schema = {
|
||||
dependencies: {
|
||||
a: ['c'],
|
||||
b: ['d']
|
||||
}
|
||||
};
|
||||
|
||||
var obj = { a: 1, c: 3 };
|
||||
var proto = { b: 2 };
|
||||
test(schema, obj, proto);
|
||||
|
||||
obj = { a: 1, b: 2, c: 3 };
|
||||
proto = { d: 4 };
|
||||
test(schema, obj, proto, 1, true);
|
||||
});
|
||||
|
||||
it('should only validate own properties with patternProperties', function() {
|
||||
var schema = {
|
||||
patternProperties: { 'f.*o': { type: 'integer' } },
|
||||
|
|
Loading…
Reference in New Issue