Skip to content

joi.array().includes path and errors mismatch #495

@saravana01

Description

@saravana01

Joi.array().includes validation error message doesnt give the proper path and error messages are not separated by fields.

test

var schema = Joi.object({
  test: Joi.array().includes(Joi.object().keys({
    foo: Joi.string().required().max(3),
    bar: Joi.string().max(5)
  }))
});

var value = {
  test: [{
    foo: 'test1',
    bar: 'testfailed'
  }]
};

Joi.validate(value, schema, {abortEarly: false}, function (err, value) {
  console.log(err);
});

result:

{ [ValidationError: test position 0 fails because foo length must be less than or equal to 3 characters long, bar length must be less than or equal to 5 characters long]
  name: 'ValidationError',
  details: 
   [ { message: 'test position 0 fails because foo length must be less than or equal to 3 characters long, bar length must be less than or equal to 5 characters long',
       path: 'test.0.foo',
       type: 'array.includesOne' } ],
  _object: { test: [ [Object] ] },
  annotate: [Function] }

Expecting two error messages. First path should show test.0.foo followed by test.0.bar.

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codebugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions