feat: support dependencies keyword with empty array of required properties, #367

master
Evgeny Poberezkin 2016-12-24 16:21:34 +00:00
parent 18a5e56f31
commit 559efa2b49
3 changed files with 65 additions and 11 deletions

View File

@ -23,17 +23,19 @@ var {{=$errs}} = errors;
var missing{{=$lvl}};
{{ for (var $property in $propertyDeps) { }}
{{ $deps = $propertyDeps[$property]; }}
if ({{=$data}}{{= it.util.getProperty($property) }} !== undefined
{{? $breakOnError }}
&& ({{# def.checkMissingProperty:$deps }})) {
{{# def.errorMissingProperty:'dependencies' }}
{{??}}
) {
{{~ $deps:$reqProperty }}
{{# def.allErrorsMissingProperty:'dependencies' }}
{{~}}
{{?}}
} {{# def.elseIfValid }}
{{? $deps.length }}
if ({{=$data}}{{= it.util.getProperty($property) }} !== undefined
{{? $breakOnError }}
&& ({{# def.checkMissingProperty:$deps }})) {
{{# def.errorMissingProperty:'dependencies' }}
{{??}}
) {
{{~ $deps:$reqProperty }}
{{# def.allErrorsMissingProperty:'dependencies' }}
{{~}}
{{?}}
} {{# def.elseIfValid }}
{{?}}
{{ } }}
{{

View File

@ -0,0 +1,27 @@
[
{
"description": "dependencies keyword with empty array",
"schema": {
"dependencies": {
"foo": []
}
},
"tests": [
{
"description": "object with property is valid",
"data": { "foo": 1 },
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
},
{
"description": "non-object is valid",
"data": 1,
"valid": true
}
]
}
]

View File

@ -0,0 +1,25 @@
[
{
"description": "required keyword with empty array",
"schema": {
"required": []
},
"tests": [
{
"description": "object with property is valid",
"data": { "foo": 1 },
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
},
{
"description": "non-object is valid",
"data": 1,
"valid": true
}
]
}
]