fix: ownProperties option with required keyword, #197
parent
57fc360285
commit
df6ef691ae
|
@ -180,3 +180,16 @@
|
|||
if (!Object.prototype.hasOwnProperty.call({{=$data}}, {{=$key}})) continue;
|
||||
{{?}}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.noPropertyInData:
|
||||
{{=$useData}} === undefined
|
||||
{{? $ownProperties }}
|
||||
|| !{{# def.isOwnProperty }}
|
||||
{{?}}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.isOwnProperty:
|
||||
Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
|
||||
#}}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
{{
|
||||
var $schemaDeps = {}
|
||||
, $propertyDeps = {};
|
||||
, $propertyDeps = {}
|
||||
, $ownProperties = it.opts.ownProperties;
|
||||
|
||||
for ($property in $schema) {
|
||||
var $sch = $schema[$property];
|
||||
|
@ -30,7 +31,7 @@ var missing{{=$lvl}};
|
|||
{{# def.errorMissingProperty:'dependencies' }}
|
||||
{{??}}
|
||||
) {
|
||||
{{~ $deps:$reqProperty }}
|
||||
{{~ $deps:$propertyKey }}
|
||||
{{# def.allErrorsMissingProperty:'dependencies' }}
|
||||
{{~}}
|
||||
{{?}}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
{{## def.checkMissingProperty:_properties:
|
||||
{{~ _properties:_$property:$i }}
|
||||
{{~ _properties:$propertyKey:$i }}
|
||||
{{?$i}} || {{?}}
|
||||
{{ var $prop = it.util.getProperty(_$property); }}
|
||||
( {{=$data}}{{=$prop}} === undefined && (missing{{=$lvl}} = {{= it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop) }}) )
|
||||
{{
|
||||
var $prop = it.util.getProperty($propertyKey)
|
||||
, $useData = $data + $prop;
|
||||
}}
|
||||
( ({{# def.noPropertyInData }}) && (missing{{=$lvl}} = {{= it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop) }}) )
|
||||
{{~}}
|
||||
#}}
|
||||
|
||||
|
@ -20,15 +23,17 @@
|
|||
{{# def.error:_error }}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.allErrorsMissingProperty:_error:
|
||||
{{
|
||||
var $prop = it.util.getProperty($reqProperty)
|
||||
, $missingProperty = it.util.escapeQuotes($reqProperty);
|
||||
var $prop = it.util.getProperty($propertyKey)
|
||||
, $missingProperty = it.util.escapeQuotes($propertyKey)
|
||||
, $useData = $data + $prop;
|
||||
if (it.opts._errorDataPathProperty) {
|
||||
it.errorPath = it.util.getPath($currentErrorPath, $reqProperty, it.opts.jsonPointers);
|
||||
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
||||
}
|
||||
}}
|
||||
if ({{=$data}}{{=$prop}} === undefined) {
|
||||
if ({{# def.noPropertyInData }}) {
|
||||
{{# def.addError:_error }}
|
||||
}
|
||||
#}}
|
||||
|
|
|
@ -21,19 +21,6 @@
|
|||
#}}
|
||||
|
||||
|
||||
{{## def.noPropertyInData:
|
||||
{{=$useData}} === undefined
|
||||
{{? $ownProperties }}
|
||||
|| !{{# def.isOwnProperty }}
|
||||
{{?}}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.isOwnProperty:
|
||||
Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
|
||||
#}}
|
||||
|
||||
|
||||
{{
|
||||
var $key = 'key' + $lvl
|
||||
, $dataNxt = $it.dataLevel = it.dataLevel + 1
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
{{? $isData || $required.length }}
|
||||
{{
|
||||
var $currentErrorPath = it.errorPath
|
||||
, $loopRequired = $isData || $required.length >= it.opts.loopRequired;
|
||||
, $loopRequired = $isData || $required.length >= it.opts.loopRequired
|
||||
, $ownProperties = it.opts.ownProperties;
|
||||
}}
|
||||
|
||||
{{? $breakOnError }}
|
||||
|
@ -83,7 +84,7 @@
|
|||
|
||||
{{? $isData }} } {{?}}
|
||||
{{??}}
|
||||
{{~ $required:$reqProperty }}
|
||||
{{~ $required:$propertyKey }}
|
||||
{{# def.allErrorsMissingProperty:'required' }}
|
||||
{{~}}
|
||||
{{?}}
|
||||
|
|
|
@ -117,7 +117,7 @@ describe('Ajv Options', function () {
|
|||
test(schema, obj, proto);
|
||||
});
|
||||
|
||||
it.skip('should only validate own properties with required keyword', function() {
|
||||
it('should only validate own properties with required keyword', function() {
|
||||
var schema = {
|
||||
required: ['a', 'b']
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue