From 0d13db6eb04b625ace4a9b4b6c2102e63e643573 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 24 Jun 2020 15:02:56 -0700 Subject: [PATCH] Fix removeAdditional option of ajv --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3f5fd8f..58c24b9 100644 --- a/index.js +++ b/index.js @@ -195,8 +195,10 @@ const validateResponse = (req, res, next) => { } } + val = _.cloneDeep(val); + const validator = ajv.compile(responseSchema); - const validation = validator(_.cloneDeep(val)); + const validation = validator(val); if (!validation) { debug(` Response validation errors: \n${util.inspect(validator.errors)}`); if (options.responseValidationFn) { @@ -244,8 +246,10 @@ const validateRequest = (req, res, next) => { next(); } } else { + req.body = _.cloneDeep(req.body); + const validator = ajv.compile(requestSchema); - const validation = validator(_.cloneDeep(req.body)); + const validation = validator(req.body); if (!validation) { debug(` Request validation errors: \n${util.inspect(validator.errors)}`); if (options.requestValidationFn) {