diff --git a/lib/dot/anyOf.jst b/lib/dot/anyOf.jst index 93c3cd8..086cf2b 100644 --- a/lib/dot/anyOf.jst +++ b/lib/dot/anyOf.jst @@ -35,7 +35,7 @@ {{= $closingBraces }} if (!{{=$valid}}) { - {{# def.addError:'anyOf' }} + {{# def.extraError:'anyOf' }} } else { {{# def.resetErrors }} {{? it.opts.allErrors }} } {{?}} diff --git a/lib/dot/oneOf.jst b/lib/dot/oneOf.jst index b7f7bff..59a4355 100644 --- a/lib/dot/oneOf.jst +++ b/lib/dot/oneOf.jst @@ -38,7 +38,7 @@ var {{=$valid}} = false; {{= $closingBraces }} if (!{{=$valid}}) { - {{# def.error:'oneOf' }} + {{# def.extraError:'oneOf' }} } else { {{# def.resetErrors }} {{? it.opts.allErrors }} } {{?}} diff --git a/spec/errors.spec.js b/spec/errors.spec.js index c96f903..7e83538 100644 --- a/spec/errors.spec.js +++ b/spec/errors.spec.js @@ -459,7 +459,7 @@ describe('Validation errors', function () { }); - it('should has correct schema path for additionalItems', function() { + it('should have correct schema path for additionalItems', function() { var schema = { type: 'array', items: [ { type: 'integer' }, { type: 'integer' } ], @@ -518,6 +518,53 @@ describe('Validation errors', function () { }); + describe('oneOf errors', function() { + it('should have errors from inner schemas', function() { + var schema = { + oneOf: [ + { type: 'number' }, + { type: 'integer' } + ] + }; + + test(ajv); + test(fullAjv); + + function test(_ajv) { + var validate = _ajv.compile(schema); + validate('foo') .should.equal(false); + validate.errors.length .should.equal(3); + validate(1) .should.equal(false); + validate.errors.length .should.equal(1); + validate(1.5) .should.equal(true); + } + }); + }); + + + describe('anyOf errors', function() { + it('should have errors from inner schemas', function() { + var schema = { + anyOf: [ + { type: 'number' }, + { type: 'integer' } + ] + }; + + test(ajv); + test(fullAjv); + + function test(_ajv) { + var validate = _ajv.compile(schema); + validate('foo') .should.equal(false); + validate.errors.length .should.equal(3); + validate(1) .should.equal(true); + validate(1.5) .should.equal(true); + } + }); + }); + + function testSchema1(schema, schemaPathPrefix) { _testSchema1(ajv, schema, schemaPathPrefix); _testSchema1(ajvJP, schema, schemaPathPrefix);