Skip to content

Commit

Permalink
Merge 2358d44 into 521c3a5
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix He committed Jul 13, 2020
2 parents 521c3a5 + 2358d44 commit be4df90
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/dot/custom.jst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ var {{=$valid}};
if (vErrors === null) vErrors = {{=$ruleErrs}};
else vErrors = vErrors.concat({{=$ruleErrs}});
errors = vErrors.length;
{{# def.extendErrors:false }}
{{? $rDef.errors != 'full' }}
{{# def.extendErrors:false }}
{{?}}
} else {
{{= def_customError }}
}
Expand Down
43 changes: 43 additions & 0 deletions spec/issues/1244_custom_validate_should_skip_extenderrors.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

var Ajv = require('../ajv');
require('../chai').should();


describe('issue #1244: Should skip extendError if "error" option is "full"', function() {
it('should skip extendError if "error" option is "full"', function() {
var ajv = new Ajv({
verbose: true
});
ajv.addKeyword("propertyMustBeTrue", {
// eslint-disable-next-line no-unused-vars
validate: function v(schema, data, _parentSchema, dataPath) {
if (data && !data[schema]) {
v.errors = [{
keyword: "propertyMustBeTrue",
dataPath: dataPath + "." + schema,
data: data[schema]
}];
return false;
}
return true;
},
errors: "full",
metaSchema: { type: "string" }
});

var schema = {
properties: {
a: { type: "boolean" },
},
propertyMustBeTrue: "a"
};
var data = { a: false };

var validate = ajv.compile(schema);
validate(data) .should.equal(false);
validate.errors.length .should.equal(1);
validate.errors[0].data .should.equal(false);
validate.errors[0].dataPath .should.equal(".a");
});
});

0 comments on commit be4df90

Please sign in to comment.