fixed incorrect dataPath in errors for refs, closes #9
parent
993e2a73d7
commit
536d958cf1
|
@ -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}}{{?}}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ajv",
|
||||
"version": "0.4.8",
|
||||
"version": "0.4.9",
|
||||
"description": "Another JSON schema Validator",
|
||||
"main": "lib/ajv.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue