From 0ff927fe2c8f221957680058616b62d44a069233 Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Thu, 15 Dec 2016 19:00:22 +0100 Subject: [PATCH] Make validate support optional fields --- src/verify.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/verify.js b/src/verify.js index c56ebdcd9..9eae796dc 100644 --- a/src/verify.js +++ b/src/verify.js @@ -240,6 +240,9 @@ verify.generate = function generate(mtype) { var field = fields[i].resolve(), prop = util.safeProp(field.name); + if (field.optional) + gen("if(m===null || m===undefined) return null"); + // map fields if (field.map) { gen ("if(m%s!==undefined){", prop)