41 lines
895 B
JavaScript
41 lines
895 B
JavaScript
'use strict';
|
|
|
|
var Ajv = require('../ajv');
|
|
require('../chai').should();
|
|
|
|
|
|
describe('issue #8: schema with shared references', function() {
|
|
it('should be supported by addSchema', spec('addSchema'));
|
|
|
|
it('should be supported by compile', spec('compile'));
|
|
|
|
function spec(method) {
|
|
return function() {
|
|
var ajv = new Ajv;
|
|
|
|
var propertySchema = {
|
|
type: 'string',
|
|
maxLength: 4
|
|
};
|
|
|
|
var schema = {
|
|
$id: 'obj.json#',
|
|
type: 'object',
|
|
properties: {
|
|
foo: propertySchema,
|
|
bar: propertySchema
|
|
}
|
|
};
|
|
|
|
ajv[method](schema);
|
|
|
|
var result = ajv.validate('obj.json#', { foo: 'abc', bar: 'def' });
|
|
result .should.equal(true);
|
|
|
|
result = ajv.validate('obj.json#', { foo: 'abcde', bar: 'fghg' });
|
|
result .should.equal(false);
|
|
ajv.errors .should.have.length(1);
|
|
};
|
|
}
|
|
});
|