From 7a2027652b8f443a9247dbb85ef0e988bbddb3ab Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 7 Oct 2019 14:59:34 -0400 Subject: [PATCH] fix(schema): handle `required: null` and `required: undefined` as `required: false` Fix #8219 --- lib/schematype.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/schematype.js b/lib/schematype.js index 2cd0caf0858..fbce0e0dce6 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -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;