Enums With Invalid
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Context
* *node version*: 16.13.1
* *module version*: 17.6.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:
#### How can we help?
Hi, as mentioned in #2526, it seems like Joi.valid() is what we should use for checking aginst an enum. I also understand that mixing the use of invalid() and valid() could easily result in errors.
Say I have a request with two inputs, prev and current, both of them need to adhere to some sort of enum. Since this request signals a change in state, prev and current must be different. Is there any way to achieve this goal?
```js
const some = Joi.object({
prev: Joi.string().valid(
"enum1",
"enum2"
).required(),
current: Joi.string().invalid(Joi.ref("prev")).valid(
"enum1",
"enum2"
).required(),
}).options({
abortEarly: true
});
```
Contributor guide
Assessment
This issue has not been assessed yet.