removed compiled dot templates from the repo, #34

master
Evgeny Poberezkin 2015-08-22 22:15:28 +01:00
parent f9017a54d3
commit 1c508fa98c
27 changed files with 9 additions and 1372 deletions

3
.gitignore vendored
View File

@ -28,6 +28,9 @@ node_modules
.DS_Store
# Compiled templates
lib/dotjs/*.js
# Browserified tests
.browser

View File

@ -1,3 +1,3 @@
These files are compiled dot templates from dot folder.
Do NOT edit them directly, edit the templates and run `node bin/compile_dots` from main ajv folder.
Do NOT edit them directly, edit the templates and run `npm run build` from main ajv folder.

View File

@ -1,37 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['allOf'],
$schemaPath = it.schemaPath + '.' + 'allOf',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
var arr1 = $schema;
if (arr1) {
var $sch, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$sch = arr1[$i += 1];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
out += ' ' + (it.validate($it)) + ' ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
}
}
if ($breakOnError) {
out += ' ' + ($closingBraces.slice(0, -1));
}
out = it.util.cleanUpCode(out);
return out;
}

View File

@ -1,47 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['anyOf'],
$schemaPath = it.schemaPath + '.' + 'anyOf',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
var $noEmptySchema = $schema.every(function($sch) {
return it.util.schemaHasRules($sch, it.RULES.all);
});
if ($noEmptySchema) {
out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
var arr1 = $schema;
if (arr1) {
var $sch, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$sch = arr1[$i += 1];
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
out += ' ' + (it.validate($it)) + ' ' + ($valid) + ' = ' + ($valid) + ' || valid' + ($it.level) + '; if (!' + ($valid) + ') { ';
$closingBraces += '}';
}
}
out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = { keyword: \'' + ('anyOf') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match some schema in anyOf\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
if (it.opts.allErrors) {
out += ' } ';
}
out = it.util.cleanUpCode(out);
} else {
if ($breakOnError) {
out += ' if (true) { ';
}
}
return out;
}

View File

@ -1,90 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['dependencies'],
$schemaPath = it.schemaPath + '.' + 'dependencies',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
var $schemaDeps = {},
$propertyDeps = {};
for ($property in $schema) {
var $sch = $schema[$property];
var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
$deps[$property] = $sch;
}
out += 'var ' + ($errs) + ' = errors;';
for (var $property in $propertyDeps) {
out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined) { ';
$deps = $propertyDeps[$property];
out += ' if ( ';
var arr1 = $deps;
if (arr1) {
var $dep, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$dep = arr1[$i += 1];
if ($i) {
out += ' || ';
}
out += ' ' + ($data) + (it.util.getProperty($dep)) + ' === undefined ';
}
}
out += ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('dependencies') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'';
if ($deps.length == 1) {
out += 'property ' + (it.util.escapeQuotes($deps[0])) + ' is';
} else {
out += 'properties ' + (it.util.escapeQuotes($deps.join(", "))) + ' are';
}
out += ' required when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('dependencies') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'';
if ($deps.length == 1) {
out += 'property ' + (it.util.escapeQuotes($deps[0])) + ' is';
} else {
out += 'properties ' + (it.util.escapeQuotes($deps.join(", "))) + ' are';
}
out += ' required when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } ';
if ($breakOnError) {
$closingBraces += '}';
out += ' else { ';
}
out += ' }';
}
for (var $property in $schemaDeps) {
var $sch = $schemaDeps[$property];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { ';
$it.schema = $sch;
$it.schemaPath = $schemaPath + it.util.getProperty($property);
out += ' ' + (it.validate($it)) + ' } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
}
if ($breakOnError) {
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
}
out = it.util.cleanUpCode(out);
return out;
}

View File

@ -1,32 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['enum'],
$schemaPath = it.schemaPath + '.' + 'enum',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $i = 'i' + $lvl;
out += 'var enumSchema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ' , ' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<enumSchema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', enumSchema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; } if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('enum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be equal to one of values\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('enum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be equal to one of values\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' }';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,44 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['format'],
$schemaPath = it.schemaPath + '.' + 'format',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $format = it.formats[$schema];
if (it.opts.format !== false && $format) {
out += ' if (! ';
if (typeof $format == 'function') {
out += ' formats' + (it.util.getProperty($schema)) + ' (' + ($data) + ') ';
} else {
out += ' formats' + (it.util.getProperty($schema)) + ' .test(' + ($data) + ') ';
}
out += ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('format') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match format ' + (it.util.escapeQuotes($schema)) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('format') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match format ' + (it.util.escapeQuotes($schema)) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } ';
if ($breakOnError) {
out += ' else { ';
}
} else {
if ($breakOnError) {
out += ' if (true) { ';
}
}
return out;
}

View File

@ -1,114 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['items'],
$schemaPath = it.schemaPath + '.' + 'items',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
var $dataNxt = $it.dataLevel = it.dataLevel + 1,
$nextData = 'data' + $dataNxt;
out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
if (Array.isArray($schema)) {
var $additionalItems = it.schema.additionalItems;
if ($additionalItems === false) {
out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('additionalItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: false, data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('additionalItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: false, data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } ';
if ($breakOnError) {
$closingBraces += '}';
out += ' else { ';
}
}
var arr1 = $schema;
if (arr1) {
var $sch, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$sch = arr1[$i += 1];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
$it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
var $passData = $data + '[' + $i + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
} else {
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
}
out += ' } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
}
}
if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) {
$it.schema = $additionalItems;
$it.schemaPath = it.schemaPath + '.additionalItems';
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var i' + ($lvl) + ' = ' + ($schema.length) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
$it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
var $passData = $data + '[i' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
} else {
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
}
if ($breakOnError) {
out += ' if (!valid' + ($it.level) + ') break; ';
}
out += ' } } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
} else if (it.util.schemaHasRules($schema, it.RULES.all)) {
$it.schema = $schema;
$it.schemaPath = $schemaPath;
out += ' for (var i' + ($lvl) + ' = ' + (0) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
$it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
var $passData = $data + '[i' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
} else {
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
}
if ($breakOnError) {
out += ' if (!valid' + ($it.level) + ') break; ';
}
out += ' } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
if ($breakOnError) {
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
}
out = it.util.cleanUpCode(out);
return out;
}

View File

@ -1,31 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['maxItems'],
$schemaPath = it.schemaPath + '.' + 'maxItems',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if (' + ($data) + '.length > ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('maxItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('maxItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,37 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['maxLength'],
$schemaPath = it.schemaPath + '.' + 'maxLength',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if ( ';
if (it.opts.unicode === false) {
out += ' ' + ($data) + '.length ';
} else {
out += ' ucs2length(' + ($data) + ') ';
}
out += ' > ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('maxLength') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be longer than ' + ($schema) + ' characters\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('maxLength') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be longer than ' + ($schema) + ' characters\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,31 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['maxProperties'],
$schemaPath = it.schemaPath + '.' + 'maxProperties',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if (Object.keys(' + ($data) + ').length > ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('maxProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema) + ' properties\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('maxProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have more than ' + ($schema) + ' properties\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,34 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['maximum'],
$schemaPath = it.schemaPath + '.' + 'maximum',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $exclusive = it.schema.exclusiveMaximum === true,
$op = $exclusive ? '<' : '<=',
$notOp = $exclusive ? '>=' : '>';
out += 'if (' + ($data) + ' ' + ($notOp) + ' ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('maximum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ' + ($op) + ' ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('maximum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ' + ($op) + ' ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,31 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['minItems'],
$schemaPath = it.schemaPath + '.' + 'minItems',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if (' + ($data) + '.length < ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('minItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have less than ' + ($schema) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('minItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have less than ' + ($schema) + ' items\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,37 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['minLength'],
$schemaPath = it.schemaPath + '.' + 'minLength',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if ( ';
if (it.opts.unicode === false) {
out += ' ' + ($data) + '.length ';
} else {
out += ' ucs2length(' + ($data) + ') ';
}
out += ' < ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('minLength') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be shorter than ' + ($schema) + ' characters\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('minLength') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be shorter than ' + ($schema) + ' characters\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,31 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['minProperties'],
$schemaPath = it.schemaPath + '.' + 'minProperties',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'if (Object.keys(' + ($data) + ').length < ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('minProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have less than ' + ($schema) + ' properties\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('minProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT have less than ' + ($schema) + ' properties\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,34 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['minimum'],
$schemaPath = it.schemaPath + '.' + 'minimum',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $exclusive = it.schema.exclusiveMinimum === true,
$op = $exclusive ? '>' : '>=',
$notOp = $exclusive ? '<=' : '<';
out += 'if (' + ($data) + ' ' + ($notOp) + ' ' + ($schema) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('minimum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ' + ($op) + ' ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('minimum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ' + ($op) + ' ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,31 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['multipleOf'],
$schemaPath = it.schemaPath + '.' + 'multipleOf',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
out += 'var division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schema) + ';if (' + ($data) + ' / ' + ($schema) + ' !== parseInt(division' + ($lvl) + ')) { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('multipleOf') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be multiple of ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('multipleOf') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be multiple of ' + ($schema) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,47 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['not'],
$schemaPath = it.schemaPath + '.' + 'not',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
if (it.util.schemaHasRules($schema, it.RULES.all)) {
$it.schema = $schema;
$it.schemaPath = $schemaPath;
out += ' var ' + ($errs) + ' = errors; ' + (it.validate($it)) + ' if (valid' + ($it.level) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('not') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be valid\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('not') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be valid\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
if (it.opts.allErrors) {
out += ' } ';
}
} else {
out += ' var err = { keyword: \'' + ('not') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should NOT be valid\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
if ($breakOnError) {
out += ' if (false) { ';
}
}
return out;
}

View File

@ -1,55 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['oneOf'],
$schemaPath = it.schemaPath + '.' + 'oneOf',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;';
var arr1 = $schema;
if (arr1) {
var $sch, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$sch = arr1[$i += 1];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
out += ' ' + (it.validate($it)) + ' ';
} else {
out += ' var valid' + ($it.level) + ' = true; ';
}
if ($i) {
out += ' if (valid' + ($it.level) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
$closingBraces += '}';
}
out += ' if (valid' + ($it.level) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
}
}
out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('oneOf') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match exactly one schema in oneOf\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('oneOf') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match exactly one schema in oneOf\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
if (it.opts.allErrors) {
out += ' } ';
}
return out;
}

View File

@ -1,32 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['pattern'],
$schemaPath = it.schemaPath + '.' + 'pattern',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
new RegExp($schema);
out += 'if (! /' + (it.util.escapeRegExp($schema)) + '/.test(' + ($data) + ') ) { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('pattern') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match pattern "' + (it.util.escapeQuotes($schema)) + '"\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('pattern') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should match pattern "' + (it.util.escapeQuotes($schema)) + '"\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += '} ';
if ($breakOnError) {
out += ' else { ';
}
return out;
}

View File

@ -1,170 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['properties'],
$schemaPath = it.schemaPath + '.' + 'properties',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $it = it.util.copy(it),
$closingBraces = '';
$it.level++;
var $dataNxt = $it.dataLevel = it.dataLevel + 1,
$nextData = 'data' + $dataNxt;
var $pProperties = it.schema.patternProperties || {},
$pPropertyKeys = Object.keys($pProperties),
$aProperties = it.schema.additionalProperties,
$noAdditional = $aProperties === false,
$additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
$removeAdditional = it.opts.removeAdditional,
$checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional;
out += 'var ' + ($errs) + ' = errors;var valid' + ($it.level) + ' = true;';
if ($checkAdditional) {
out += ' var propertiesSchema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ' || {}; for (var key' + ($lvl) + ' in ' + ($data) + ') { var isAdditional' + ($lvl) + ' = propertiesSchema' + ($lvl) + '[key' + ($lvl) + '] === undefined; ';
if ($pPropertyKeys.length) {
out += ' if (isAdditional' + ($lvl) + ') { ';
var arr1 = $pPropertyKeys;
if (arr1) {
var $pProperty, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$pProperty = arr1[$i += 1];
out += ' if (/' + (it.util.escapeRegExp($pProperty)) + '/.test(key' + ($lvl) + ')) isAdditional' + ($lvl) + ' = false; ';
if ($i < $pPropertyKeys.length - 1) {
out += ' else ';
}
}
}
out += ' } ';
}
out += ' if (isAdditional' + ($lvl) + ') { ';
if ($removeAdditional == 'all') {
out += ' delete ' + ($data) + '[key' + ($lvl) + ']; ';
} else {
var $currentErrorPath = it.errorPath;
it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
if ($noAdditional) {
if ($removeAdditional) {
out += ' delete ' + ($data) + '[key' + ($lvl) + ']; ';
} else {
out += ' valid' + ($it.level) + ' = false; ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('additionalProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'additional properties NOT allowed\' ';
if (it.opts.verbose) {
out += ', schema: false, data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('additionalProperties') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'additional properties NOT allowed\' ';
if (it.opts.verbose) {
out += ', schema: false, data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
if ($breakOnError) {
out += ' break; ';
}
}
} else if ($additionalIsSchema) {
if ($removeAdditional == 'failing') {
out += ' var ' + ($errs) + ' = errors; ';
}
$it.schema = $aProperties;
$it.schemaPath = it.schemaPath + '.additionalProperties';
$it.errorPath = it.errorPath;
var $passData = $data + '[key' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
} else {
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
}
if ($removeAdditional == 'failing') {
out += ' if (!valid' + ($it.level) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[key' + ($lvl) + ']; } ';
} else {
if ($breakOnError) {
out += ' if (!valid' + ($it.level) + ') break; ';
}
}
}
it.errorPath = $currentErrorPath;
}
out += ' } } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
if ($schema) {
for (var $propertyKey in $schema) {
var $sch = $schema[$propertyKey];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
$it.schema = $sch;
var $prop = it.util.getProperty($propertyKey),
$passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
$code = it.util.varReplace($code, $nextData, $passData);
var $useData = $passData;
} else {
var $useData = $nextData;
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
}
if ($breakOnError) {
out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = true; } else { ';
} else {
out += ' if (' + ($useData) + ' !== undefined) { ';
}
out += ' ' + ($code) + ' } ';
}
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
}
var arr2 = $pPropertyKeys;
if (arr2) {
var $pProperty, i2 = -1,
l2 = arr2.length - 1;
while (i2 < l2) {
$pProperty = arr2[i2 += 1];
var $sch = $pProperties[$pProperty];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
$it.schema = $sch;
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { if (/' + (it.util.escapeRegExp($pProperty)) + '/.test(key' + ($lvl) + ')) { ';
$it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
var $passData = $data + '[key' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
} else {
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
}
if ($breakOnError) {
out += ' if (!valid' + ($it.level) + ') break; ';
}
out += ' } ';
if ($breakOnError) {
out += ' else valid' + ($it.level) + ' = true; ';
}
out += ' } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';
$closingBraces += '}';
}
}
}
}
if ($breakOnError) {
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
}
out = it.util.cleanUpCode(out);
return out;
}

View File

@ -1,82 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['$ref'],
$schemaPath = it.schemaPath + '.' + '$ref',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
if ($schema == '#' || $schema == '#/') {
if (it.isRoot) {
if ($breakOnError && it.wasTop) {
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) return false; else { ';
} else {
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ('validate') + '.errors; else vErrors = vErrors.concat(' + ('validate') + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}
}
} else {
out += ' if (! ' + ('root.refVal[0]') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ('root.refVal[0]') + '.errors; else vErrors = vErrors.concat(' + ('root.refVal[0]') + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}
}
} else {
var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
if ($refVal === undefined) {
var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId;
if (it.opts.missingRefs == 'fail') {
console.log($message);
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('$ref') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('$ref') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
if (it.opts.verbose) {
out += ', schema: ' + (it.util.toQuotedString($schema)) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
if ($breakOnError) {
out += ' if (false) { ';
}
} else if (it.opts.missingRefs == 'ignore') {
console.log($message);
if ($breakOnError) {
out += ' if (true) { ';
}
} else {
throw new Error($message);
}
} else {
out += ' if (! ' + ($refVal) + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ($refVal) + '.errors; else vErrors = vErrors.concat(' + ($refVal) + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}
}
}
return out;
}

View File

@ -1,103 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['required'],
$schemaPath = it.schemaPath + '.' + 'required',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
var $currentErrorPath = it.errorPath;
if ($breakOnError) {
out += ' var missing' + ($lvl) + '; ';
if ($schema.length <= 20) {
out += ' if ( ';
var arr1 = $schema;
if (arr1) {
var $property, $i = -1,
l1 = arr1.length - 1;
while ($i < l1) {
$property = arr1[$i += 1];
if ($i) {
out += ' || ';
}
var $prop = it.util.getProperty($property);
out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $property : $prop)) + ') ) ';
}
}
out += ') { ';
var $propertyPath = 'missing' + $lvl,
$missingProperty = '\' + ' + $propertyPath + ' + \'';
it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } else { ';
} else {
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
var $i = 'i' + $lvl,
$propertyPath = 'schema' + $lvl + '[' + $i + ']',
$missingProperty = '\' + "\'" + ' + $propertyPath + ' + "\'" + \'';
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { var ' + ($valid) + ' = ' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } else { ';
}
} else {
if ($schema.length <= 10) {
var arr2 = $schema;
if (arr2) {
var $property, $i = -1,
l2 = arr2.length - 1;
while ($i < l2) {
$property = arr2[$i += 1];
var $prop = it.util.getProperty($property),
$missingProperty = it.util.escapeQuotes($prop);
it.errorPath = it.util.getPath($currentErrorPath, $property, it.opts.jsonPointers);
out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
}
}
} else {
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
var $i = 'i' + $lvl,
$propertyPath = 'schema' + $lvl + '[' + $i + ']',
$missingProperty = '\' + "\'" + ' + $propertyPath + ' + "\'" + \'';
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
if (it.opts.verbose) {
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
}
}
it.errorPath = $currentErrorPath;
return out;
}

View File

@ -1,37 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = ' ';
var $lvl = it.level,
$dataLvl = it.dataLevel,
$schema = it.schema['uniqueItems'],
$schemaPath = it.schemaPath + '.' + 'uniqueItems',
$breakOnError = !it.opts.allErrors;
var $data = 'data' + ($dataLvl || ''),
$valid = 'valid' + $lvl,
$errs = 'errs' + $lvl;
if ($schema && it.opts.uniqueItems !== false) {
out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('uniqueItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'items ## \' + j + \' and \' + i + \' are duplicate\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('uniqueItems') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'items ## \' + j + \' and \' + i + \' are duplicate\' ';
if (it.opts.verbose) {
out += ', schema: ' + ($schema) + ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } ';
if ($breakOnError) {
out += ' else { ';
}
} else {
if ($breakOnError) {
out += ' if (true) { ';
}
}
return out;
}

View File

@ -1,182 +0,0 @@
'use strict';
module.exports = function anonymous(it) {
var out = '';
if (it.isTop) {
var $top = it.isTop,
$lvl = it.level = 0,
$dataLvl = it.dataLevel = 0,
$data = 'data';
it.rootId = it.baseId = it.resolve.fullPath(it.root.schema.id);
delete it.isTop;
it.wasTop = true;
out += ' validate = function (data, dataPath) { \'use strict\'; var vErrors = null; ';
out += ' var errors = 0; ';
} else {
var $lvl = it.level,
$dataLvl = it.dataLevel,
$data = 'data' + ($dataLvl || '');
if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
delete it.wasTop;
out += ' var errs_' + ($lvl) + ' = errors;';
}
var $valid = 'valid' + $lvl,
$breakOnError = !it.opts.allErrors,
$closingBraces1 = '',
$closingBraces2 = '';
var $typeSchema = it.schema.type;
var arr1 = it.RULES;
if (arr1) {
var $rulesGroup, i1 = -1,
l1 = arr1.length - 1;
while (i1 < l1) {
$rulesGroup = arr1[i1 += 1];
if ($shouldUseGroup($rulesGroup)) {
if ($rulesGroup.type) {
out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
}
var arr2 = $rulesGroup.rules;
if (arr2) {
var $rule, i2 = -1,
l2 = arr2.length - 1;
while (i2 < l2) {
$rule = arr2[i2 += 1];
if ($shouldUseRule($rule)) {
out += ' ' + ($rule.code(it)) + ' ';
if ($breakOnError) {
$closingBraces1 += '}';
}
}
}
}
if ($breakOnError) {
out += ' ' + ($closingBraces1) + ' ';
$closingBraces1 = '';
}
if ($rulesGroup.type) {
out += ' } ';
if ($typeSchema && $typeSchema === $rulesGroup.type) {
var $typeChecked = true;
out += ' else { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('type') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ';
if ($isArray) {
out += '' + ($typeSchema.join(","));
} else {
out += '' + ($typeSchema);
}
out += '\' ';
if (it.opts.verbose) {
out += ', schema: ';
if ($isArray) {
out += 'validate.schema' + ($schemaPath);
} else {
out += '\'' + ($typeSchema) + '\'';
}
out += ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('type') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ';
if ($isArray) {
out += '' + ($typeSchema.join(","));
} else {
out += '' + ($typeSchema);
}
out += '\' ';
if (it.opts.verbose) {
out += ', schema: ';
if ($isArray) {
out += 'validate.schema' + ($schemaPath);
} else {
out += '\'' + ($typeSchema) + '\'';
}
out += ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' } ';
}
}
if ($breakOnError) {
out += ' if (errors === ';
if ($top) {
out += '0';
} else {
out += 'errs_' + ($lvl);
}
out += ') { ';
$closingBraces2 += '}';
}
}
}
}
if ($typeSchema && !$typeChecked) {
var $schemaPath = it.schemaPath + '.type',
$isArray = Array.isArray($typeSchema),
$method = $isArray ? 'checkDataTypes' : 'checkDataType';
out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('type') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ';
if ($isArray) {
out += '' + ($typeSchema.join(","));
} else {
out += '' + ($typeSchema);
}
out += '\' ';
if (it.opts.verbose) {
out += ', schema: ';
if ($isArray) {
out += 'validate.schema' + ($schemaPath);
} else {
out += '\'' + ($typeSchema) + '\'';
}
out += ', data: ' + ($data);
}
out += ' }]; return false; ';
} else {
out += ' var err = { keyword: \'' + ('type') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be ';
if ($isArray) {
out += '' + ($typeSchema.join(","));
} else {
out += '' + ($typeSchema);
}
out += '\' ';
if (it.opts.verbose) {
out += ', schema: ';
if ($isArray) {
out += 'validate.schema' + ($schemaPath);
} else {
out += '\'' + ($typeSchema) + '\'';
}
out += ', data: ' + ($data);
}
out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
out += ' }';
}
if ($breakOnError) {
out += ' ' + ($closingBraces2) + ' ';
}
if ($top) {
out += ' validate.errors = vErrors; ';
out += ' return errors === 0; ';
out += ' }';
} else {
out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
}
out = it.util.cleanUpCode(out);
if ($top && $breakOnError) {
out = it.util.cleanUpVarErrors(out);
}
function $shouldUseGroup($rulesGroup) {
return $rulesGroup.rules.some(function($rule) {
return $shouldUseRule($rule);
});
}
function $shouldUseRule($rule) {
return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties !== undefined || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length)));
}
return out;
}

View File

@ -9,7 +9,7 @@
"bundle": "browserify -r ./lib/ajv.js:ajv -o ajv.bundle.js",
"build": "node scripts/compile-dots.js",
"test-browser": "scripts/prepare-tests && karma start --single-run --browsers PhantomJS",
"test": "npm run test-cov && npm run test-browser",
"test": "npm run build && npm run test-cov && npm run test-browser",
"prepublish": "npm run build",
"watch": "watch 'npm run build' ./lib/dot"
},

View File

@ -9,6 +9,9 @@ var glob = require('glob')
var defs = fs.readFileSync(path.join(__dirname, '../lib/dot/definitions.def'));
var files = glob.sync('../lib/dot/*.jst', { cwd: __dirname });
var dotjsPath = path.join(__dirname, '../lib/dotjs');
try { fs.mkdirSync(dotjsPath); } catch(e) {}
console.log('\n\nCompiling:');
files.forEach(function (f) {
@ -18,7 +21,7 @@ files.forEach(function (f) {
code = code.replace(/out\s*\+=\s*'\s*';/g, '');
code = beautify(code, { indent_size: 2 }) + '\n';
var targetFile = f.replace('../lib/dot', '').replace('.jst', '.js')
, targetPath = path.join(__dirname, '../lib/dotjs', targetFile);
, targetPath = path.join(dotjsPath, targetFile);
fs.writeFileSync(targetPath, code);
console.log('compiled', targetFile);
});