Comparing version 0.4.14 to 0.4.15
@@ -44,5 +44,10 @@ {{# def.definitions }} | ||
if (isAdditional{{=$lvl}}) { | ||
if (isAdditional{{=$lvl}}) { | ||
{{ | ||
var $currentErrorPath = it.errorPath; | ||
it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
}} | ||
{{? $noAdditional }} | ||
valid{{=$it.level}} = false; | ||
{{# def.error:'additionalProperties' }} | ||
@@ -54,3 +59,3 @@ {{? $breakOnError }} break; {{?}} | ||
$it.schemaPath = it.schemaPath + '.additionalProperties'; | ||
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
$it.errorPath = it.errorPath; | ||
$it.dataPath = it.dataPath + '[key' + $lvl + ']'; | ||
@@ -65,2 +70,3 @@ var $passData = $data + '[key' + $lvl + ']'; | ||
{{?}} | ||
{{ it.errorPath = $currentErrorPath; }} | ||
} | ||
@@ -67,0 +73,0 @@ } |
{ | ||
"name": "ajv", | ||
"version": "0.4.14", | ||
"version": "0.4.15", | ||
"description": "Another JSON schema Validator", | ||
@@ -5,0 +5,0 @@ "main": "lib/ajv.js", |
@@ -9,10 +9,11 @@ 'use strict'; | ||
describe('Validation errors', function () { | ||
var ajv; | ||
var ajv, fullAjv; | ||
beforeEach(function() { | ||
ajv = Ajv(); | ||
fullAjv = Ajv({ allErrors: true }); | ||
}); | ||
it('error should include dataPath', function() { | ||
testSchema({ | ||
testSchema1({ | ||
properties: { | ||
@@ -25,3 +26,3 @@ foo: { type: 'number' } | ||
it('error should include dataPath in refs', function() { | ||
testSchema({ | ||
testSchema1({ | ||
definitions: { | ||
@@ -37,3 +38,34 @@ num: { type: 'number' } | ||
function testSchema(schema) { | ||
it('errors for additionalProperties should include property in dataPath', function() { | ||
var schema = { | ||
properties: { | ||
foo: {}, | ||
bar: {} | ||
}, | ||
additionalProperties: false | ||
}; | ||
var data = { foo: 1, bar: 2 } | ||
, invalidData = { foo: 1, bar: 2, baz: 3, quux: 4 }; | ||
var validate = ajv.compile(schema); | ||
shouldBeValid(validate, data); | ||
shouldBeInvalid(validate, invalidData); | ||
shouldBeError(validate.errors[0], 'additionalProperties', "['baz']"); | ||
var fullValidate = fullAjv.compile(schema); | ||
shouldBeValid(fullValidate, data); | ||
shouldBeInvalid(fullValidate, invalidData, 2); | ||
shouldBeError(fullValidate.errors[0], 'additionalProperties', "['baz']"); | ||
shouldBeError(fullValidate.errors[1], 'additionalProperties', "['quux']"); | ||
}); | ||
function testSchema1(schema) { | ||
_testSchema1(ajv, schema); | ||
_testSchema1(fullAjv, schema) | ||
} | ||
function _testSchema1(ajv, schema) { | ||
var data = { foo: 1 } | ||
@@ -43,13 +75,25 @@ , invalidData = { foo: 'bar' }; | ||
var validate = ajv.compile(schema); | ||
shouldBeValid(validate, data); | ||
shouldBeInvalid(validate, invalidData); | ||
shouldBeError(validate.errors[0], 'type', '.foo'); | ||
} | ||
function shouldBeValid(validate, data) { | ||
validate(data) .should.equal(true); | ||
should.equal(validate.errors, null); | ||
} | ||
validate(invalidData) .should.equal(false); | ||
validate.errors.length .should.equal(1); | ||
var error = validate.errors[0]; | ||
error.keyword .should.equal('type'); | ||
function shouldBeInvalid(validate, data, numErrors) { | ||
validate(data) .should.equal(false); | ||
validate.errors.length .should.equal(numErrors || 1); | ||
} | ||
function shouldBeError(error, keyword, dataPath) { | ||
error.keyword .should.equal(keyword); | ||
error.message .should.be.a('string'); | ||
error.dataPath .should.equal('.foo'); | ||
error.dataPath .should.equal(dataPath); | ||
} | ||
}); |
@@ -49,3 +49,3 @@ 'use strict'; | ||
describe.only('Schema validation tests', function() { | ||
describe('Schema validation tests', function() { | ||
addTests('JSON-Schema tests draft4', './json-schema-test-suite/tests/draft4/{**/,}*.json'); | ||
@@ -52,0 +52,0 @@ addTests('Advanced schema tests', './tests/{**/,}*.json'); |
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
271732
8132