hapijs / joi

The most powerful data validation library for JS
Other
20.94k stars 1.51k forks source link

joi.allow array #3010

Closed kroney closed 10 months ago

kroney commented 10 months ago

Runtime

node.js

Runtime version

20

Module version

17.11.0

Used with

No response

Any other relevant information

No response

How can we help?

Is there a way to use .allow() specifically to allow an array, e.g.:

Joi.string().allow(['a'])
// should allow any string and ['a']
// throws Uncaught Error: Method no longer accepts array arguments: allow

I can work around this by using alternatives or conditions, but I don't understand why allow does not accept arrays.

cimbraien commented 10 months ago

If you need to allow different schemas, you can use alternative(). Docs

Marsup commented 10 months ago

allow is there to compare pure values, the moment you need to compare complex objects, you probably need schemas.