Skip to content

Continue array validation even if items() fails #1730

Description

@Thomas--S

Hello, I stumbled accross the following behavior using the joi version provided by npm:

When I set abortEarly: false, no unique error is returned if there is a previous error, e.g. from required.

Example:

console.log(Joi.validate([
    {
        test: 'test',
        hello: 'world',
    },
    {
        test: 'test',
    }
], Joi.array().items(Joi.object().keys({
    test: Joi.string(),
    hello: Joi.string(),
})).unique('test'), {abortEarly: false}).error.details);

This outputs the following as expected:

[ { message: '"value" position 1 contains a duplicate value',
    path: [ 1 ],
    type: 'array.unique',
    context:
     { pos: 1,
       value: [Object],
       dupePos: 0,
       dupeValue: [Object],
       path: 'test',
       key: 1,
       label: 'value' } } ]

However:

console.log(Joi.validate([
    {
        test: 'test',
        hello: 'world',
    },
    {
        test: 'test',
    }
], Joi.array().items(Joi.object().keys({
    test: Joi.string(),
    hello: Joi.string().required(),
})).unique('test'), {abortEarly: false}).error.details);

only outputs the following

[ { message: '"hello" is required',
    path: [ 1, 'hello' ],
    type: 'any.required',
    context: { key: 'hello', label: 'hello' } } ]

I'd expect the two errors to be returned in the second example. I'm not sure if this is a bug.

Thanks in advance for your efforts!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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