fixed incorrect dataPath in errors for refs, closes #9

master
Evgeny Poberezkin 2015-06-16 00:20:24 +01:00
parent 993e2a73d7
commit 536d958cf1
3 changed files with 53 additions and 2 deletions

View File

@ -93,7 +93,7 @@
{{## def._error:_rule:
{
keyword: '{{=_rule}}',
dataPath: {{= it.errorPath }},
dataPath: (dataPath || '') + {{= it.errorPath }},
message: {{# def._errorMessages[_rule] }}
{{? it.opts.verbose }}, schema: {{# def._errorSchemas[_rule] }}, data: {{=$data}}{{?}}
}

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "0.4.8",
"version": "0.4.9",
"description": "Another JSON schema Validator",
"main": "lib/ajv.js",
"scripts": {

51
spec/errors.spec.js Normal file
View File

@ -0,0 +1,51 @@
'use strict';
var Ajv = require('../lib/ajv')
, should = require('chai').should();
describe('Validation errors', function () {
var ajv;
beforeEach(function() {
ajv = Ajv();
});
it('error should include dataPath', function() {
testSchema({
properties: {
foo: { type: 'number' }
}
});
});
it('error should include dataPath in refs', function() {
testSchema({
definitions: {
num: { type: 'number' }
},
properties: {
foo: { $ref: '#/definitions/num' }
}
});
});
function testSchema(schema) {
var data = { foo: 1 }
, invalidData = { foo: 'bar' };
var validate = ajv.compile(schema);
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');
error.message .should.be.a('string');
error.dataPath .should.equal('.foo');
}
});