ajv/lib/dot/required.jst

83 lines
2.2 KiB
Plaintext

{{# def.definitions }}
{{# def.errors }}
{{# def.missing }}
{{# def.setup:'required' }}
{{## def.setupLoop:
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
{{
var $i = 'i' + $lvl
, $propertyPath = 'schema' + $lvl + '[' + $i + ']'
, $missingProperty = '\' + ' + $propertyPath + ' + \'';
if (it.opts._errorDataPathProperty) {
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
}
}}
#}}
{{? it.schema.properties && Object.keys(it.schema.properties).length }}
{{ var $required = []; }}
{{~ $schema:$property }}
{{ var $propertySch = it.schema.properties[$property]; }}
{{? !($propertySch && {{# def.nonEmptySchema:$propertySch}}) }}
{{ $required[$required.length] = $property; }}
{{?}}
{{~}}
{{??}}
{{ var $required = $schema; }}
{{?}}
{{? $required.length }}
{{ var $currentErrorPath = it.errorPath; }}
{{? $breakOnError }}
var missing{{=$lvl}};
{{? $required.length <= 20 }}
if ({{# def.checkMissingProperty:$required }}) {
{{# def.errorMissingProperty }}
{{# def.error:'required' }}
} else {
{{??}}
{{# def.setupLoop }}
for (var {{=$i}} = 0; {{=$i}} < schema{{=$lvl}}.length; {{=$i}}++) {
var {{=$valid}} = {{=$data}}[schema{{=$lvl}}[{{=$i}}]] !== undefined;
if (!{{=$valid}}) break;
}
{{# def.checkError:'required' }}
else {
{{?}}
{{??}}
{{? $required.length <= 20 }}
{{~ $required:$property:$i }}
{{
var $prop = it.util.getProperty($property)
, $missingProperty = it.util.escapeQuotes($property);
if (it.opts._errorDataPathProperty) {
it.errorPath = it.util.getPath($currentErrorPath, $property, it.opts.jsonPointers);
}
}}
if ({{=$data}}{{=$prop}} === undefined) {
{{# def.addError:'required' }}
}
{{~}}
{{??}}
{{# def.setupLoop }}
for (var {{=$i}} = 0; {{=$i}} < schema{{=$lvl}}.length; {{=$i}}++) {
if ({{=$data}}[schema{{=$lvl}}[{{=$i}}]] === undefined) {
{{# def.addError:'required' }}
}
}
{{?}}
{{?}}
{{ it.errorPath = $currentErrorPath; }}
{{?? $breakOnError }}
if (true) {
{{?}}