fix: support property dependecies with ownProperties option, #197

master
Evgeny Poberezkin 2017-02-12 00:02:56 +00:00
parent df6ef691ae
commit 1babc9df49
2 changed files with 20 additions and 0 deletions

View File

@ -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' }}

View File

@ -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' } },