Skip to content

Commit

Permalink
fix(schematype): deprecate isAsync option for custom validators
Browse files Browse the repository at this point in the history
Fix #6700
  • Loading branch information
vkarpov15 committed Mar 8, 2019
1 parent 2cca743 commit e940553
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const $type = require('./schema/operators/type');
const get = require('./helpers/get');
const immediate = require('./helpers/immediate');
const schemaTypeSymbol = require('./helpers/symbols').schemaTypeSymbol;
const util = require('util');
const utils = require('./utils');
const validatorErrorSymbol = require('./helpers/symbols').validatorErrorSymbol;

Expand Down Expand Up @@ -597,6 +598,11 @@ SchemaType.prototype.validate = function(obj, message, type) {
}
properties = {message: message, type: type, validator: obj};
}

if (properties.isAsync) {
handleIsAsync();
}

this.validators.push(properties);
return this;
}
Expand All @@ -620,6 +626,15 @@ SchemaType.prototype.validate = function(obj, message, type) {
return this;
};

/*!
* ignore
*/

const handleIsAsync = util.deprecate(function handleIsAsync() {},
'Mongoose: the `isAsync` option for custom validators is deprecated. Make ' +
'your async validators return a promise instead: ' +
'https://mongoosejs.com/docs/validation.html#async-custom-validators');

/**
* Adds a required validator to this SchemaType. The validator gets added
* to the front of this SchemaType's validators array using `unshift()`.
Expand Down

0 comments on commit e940553

Please sign in to comment.