hapijs / hapijs/joi

Supporting schema rules through invalid() / not()

Open
#2,604 1 comment 0 reactions 0 assignees View on GitHub
feature
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan
* *is this issue currently blocking your project?*: no
* *is this issue affecting a production system?*: no

#### Context

* *node version*: 14.16.1
* *module version*: 17.4.0
* *environment*: node
* *used with*: standalone
* *any other relevant information*: None.

#### What problem are you trying to solve?

First: thank you for this project! It is excellent.
Second: I apologize if this should be a "question" rather than a feature suggestion.

I'm looking to check if a field contains any non-`object`:

For instance:

```js
import Joi from 'joi'

const schema = Joi.object().keys({
myNonObjectKey: Joi.any().not(Joi.object()),
})
```

If I'm understanding the documentation and source correctly, it seems that `not` / `invalid` accepts a list of more literal `value`s, which means this schema doesn't work as I was hoping it would.

#### Do you have a new or modified API suggestion to solve the problem?

It would be nice if `invalid` and it's various aliases could accept a list of schema rules.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.