diff --git a/lib/dot/not.jst b/lib/dot/not.jst index 7cf8fe8..9943be8 100644 --- a/lib/dot/not.jst +++ b/lib/dot/not.jst @@ -14,9 +14,19 @@ {{# def.setCompositeRule }} - {{ $it.createErrors = false; }} + {{ + $it.createErrors = false; + var $allErrorsOption; + if ($it.opts.allErrors) { + $allErrorsOption = $it.opts.allErrors; + $it.opts.allErrors = false; + } + }} {{= it.validate($it) }} - {{ $it.createErrors = true; }} + {{ + $it.createErrors = true; + if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption; + }} {{# def.resetCompositeRule }} diff --git a/spec/options.spec.js b/spec/options.spec.js index ca330fb..62c8fd1 100644 --- a/spec/options.spec.js +++ b/spec/options.spec.js @@ -547,4 +547,49 @@ describe('Ajv Options', function () { return storeContext; } }); + + + describe('allErrors', function() { + it('should be disabled inside "not" keyword', function() { + test(Ajv(), false); + test(Ajv({ allErrors: true }), true); + + function test(ajv, allErrors) { + var format1called = false + , format2called = false; + + ajv.addFormat('format1', function() { + format1called = true; + return false; + }); + + ajv.addFormat('format2', function() { + format2called = true; + return false; + }); + + var schema1 = { + allOf: [ + { format: 'format1' }, + { format: 'format2' } + ] + }; + + ajv.validate(schema1, 'abc') .should.equal(false); + ajv.errors .should.have.length(allErrors ? 2 : 1); + format1called .should.equal(true); + format2called .should.equal(allErrors); + + var schema2 = { + not: schema1 + }; + + format1called = format2called = false; + ajv.validate(schema2, 'abc') .should.equal(true); + should.equal(ajv.errors, null); + format1called .should.equal(true); + format2called .should.equal(false); + } + }); + }); });