From 4f64d658127c2d55752d9491b59dd8eba39db7e1 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Thu, 22 Jul 2021 19:34:41 +0200 Subject: [PATCH] Fix issue with only required items. Fixes #2620. --- lib/types/array.js | 2 +- test/types/array.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/types/array.js b/lib/types/array.js index e99f94256..7682e8293 100755 --- a/lib/types/array.js +++ b/lib/types/array.js @@ -319,7 +319,7 @@ module.exports = Any.extend({ continue; } - if (schema.$_terms._inclusions.length && + if ((schema.$_terms._inclusions.length || schema.$_terms._requireds.length) && !isValid) { if (stripUnknown) { diff --git a/test/types/array.js b/test/types/array.js index 7c7c48eee..d09534beb 100755 --- a/test/types/array.js +++ b/test/types/array.js @@ -469,6 +469,19 @@ describe('array', () => { ]); }); + it('validates that values are validated when all items are required', () => { + + const schema = Joi.array().items(Joi.string().valid('one').required(), Joi.string().valid('two').required()); + Helper.validate(schema, [ + [['one', 'one', 'two', 'two', 'three'], false, { + message: '"[4]" does not match any of the allowed types', + path: [4], + type: 'array.includes', + context: { pos: 4, value: 'three', label: '[4]', key: 4 } + }] + ]); + }); + it('validates that a required value exists with abortEarly = false', () => { const schema = Joi.array()