Comparing version 0.6.9 to 0.6.10
@@ -25,3 +25,4 @@ 'use strict'; | ||
$additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length, | ||
$checkAdditional = $noAdditional || $additionalIsSchema; | ||
$checkAdditional = $noAdditional || $additionalIsSchema, | ||
$removeAdditional = it.opts.removeAdditional; | ||
out += 'var ' + ($errs) + ' = errors;var valid' + ($it.level) + ' = true;'; | ||
@@ -50,39 +51,47 @@ if ($checkAdditional) { | ||
out += ' if (isAdditional' + ($lvl) + ') { '; | ||
var $currentErrorPath = it.errorPath; | ||
it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
if ($noAdditional) { | ||
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); | ||
if ($removeAdditional == 'all') { | ||
out += ' delete ' + ($data) + '[key' + ($lvl) + ']; '; | ||
} else { | ||
var $currentErrorPath = it.errorPath; | ||
it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
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 (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; '; | ||
} | ||
if ($breakOnError) { | ||
out += ' break; '; | ||
} | ||
} | ||
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); | ||
$it.schema = $aProperties; | ||
$it.schemaPath = it.schemaPath + '.additionalProperties'; | ||
$it.errorPath = it.errorPath; | ||
$it.dataPath = it.dataPath + '[key' + $lvl + ']'; | ||
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) + ' '; | ||
} | ||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; '; | ||
if ($breakOnError) { | ||
out += ' if (!valid' + ($it.level) + ') break; '; | ||
} | ||
} | ||
if ($breakOnError) { | ||
out += ' break; '; | ||
} | ||
} else { | ||
$it.schema = $aProperties; | ||
$it.schemaPath = it.schemaPath + '.additionalProperties'; | ||
$it.errorPath = it.errorPath; | ||
$it.dataPath = it.dataPath + '[key' + $lvl + ']'; | ||
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; '; | ||
} | ||
it.errorPath = $currentErrorPath; | ||
} | ||
it.errorPath = $currentErrorPath; | ||
out += ' } } '; | ||
@@ -89,0 +98,0 @@ if ($breakOnError) { |
{ | ||
"name": "ajv", | ||
"version": "0.6.9", | ||
"version": "0.6.10", | ||
"description": "Another JSON Schema Validator", | ||
@@ -5,0 +5,0 @@ "main": "lib/ajv.js", |
@@ -110,2 +110,9 @@ # ajv - Another JSON Schema Validator | ||
## Filtering data | ||
With [option `removeAdditional`](#options) (added by [andyscott](https://github.com/andyscott)) you can filter data during the validation. | ||
This option modifies original object. | ||
## API | ||
@@ -202,2 +209,3 @@ | ||
- _allErrors_: check all rules collecting all errors. Default is to return after the first error. | ||
- _removeAdditional: remove additional properties. Default is not to remove. If the option is 'all', then all additional properties are removed, regardless of `additionalProperties` keyword in schema (and no validation is made for them). If the option is `true` (or truthy), only additional properties with `additionalProperties` keyword equal to `false` are removed. | ||
- _verbose_: include the reference to the part of the schema and validated data in errors (false by default). | ||
@@ -238,3 +246,7 @@ - _format_: formats validation mode ('fast' by default). Pass 'full' for more correct and slow validation or `false` not to validate formats at all. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode. | ||
##### 0.6.10 | ||
`removeAdditional` option allowing to remove additional properties. | ||
##### 0.6.1 | ||
@@ -241,0 +253,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
379973
167
10094
286
11