Skip to content

Embedded validators in Array().includes don't work  #178

@joshua-mcginnis

Description

@joshua-mcginnis

I discovered a possible bug in how array().include() validates nested objects (see below for each of the two use cases). Also, the fail message is cryptic.

Thus far, I've only tried this with array() and no other types.

I'd like test to be required. It should be of type array that is an array of objects that have a required field foo.

var Joi = require('joi');

var schema = {
    test: Joi.array().includes(Joi.object({
        foo: Joi.string().required()
    })).required()
}

/* passes
This passes but should fail because foo is required.
*/
console.log( Joi.validate({ test: [] }, schema) );

/* fails with bad error message
{ _errors: 
   [ { message: 'the value [object Object] in test does not match any of the allowed types',
       path: 'test' } ],
  _object: { test: [ [Object] ] },
  message: 'the value [object Object] in test does not match any of the allowed types' }
*/
console.log( Joi.validate({ test: [{'test': 'test'}] }, schema) );

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions