Skip to content

new feature: validate at least one member of an array matches a schema #554

@nlf

Description

@nlf

So, a feature I'm working on is the ability to validate that an array has at least one member that matches a given schema or set of schemas. For example:

Joi.array().contains(Joi.string().valid('a')); // array must contain the string 'a'
Joi.array().contains(Joi.string(), Joi.string()); // array must contain at least two strings
Joi.array().contains(Joi.string(), Joi.boolean()); // array must contain at least one string and one boolean

While I'm open to suggestions on how best to create this API, I think what I'm proposing makes sense.

Where I need the community's help is in naming this feature. As in the above examples, I'm proposing the name contains however that's somewhat ambiguous with the existing Joi.array().includes() method. To avoid confusion I'm opening this up for discussion so that we can, as a community, decide on what name makes the most sense here.

Some other names that have been discussed:

Joi.array().some();
Joi.array().mandatory();
Joi.array().requires();

I'm open to any and all suggestions though, let's figure this out!

Metadata

Metadata

Assignees

Labels

supportQuestions, discussions, and general support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions