Skip to content

Commit

Permalink
fix(schema): handle required: null and required: undefined as `re…
Browse files Browse the repository at this point in the history
…quired: false`

Fix #8219
  • Loading branch information
vkarpov15 committed Oct 7, 2019
1 parent 9b4a323 commit 7a20276
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,17 @@ const handleIsAsync = util.deprecate(function handleIsAsync() {},

SchemaType.prototype.required = function(required, message) {
let customOptions = {};

if (arguments.length > 0 && required == null) {
this.validators = this.validators.filter(function(v) {
return v.validator !== this.requiredValidator;
}, this);

this.isRequired = false;
delete this.originalRequiredValue;
return this;
}

if (typeof required === 'object') {
customOptions = required;
message = customOptions.message || message;
Expand Down

0 comments on commit 7a20276

Please sign in to comment.