Add support for recursive warnings
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Context
This feature requests comes from the discussion in #2669.
* *node version*:
* *module version*:
* *environment* (e.g. node, browser, native):
* *used with* (e.g. hapi application, another framework, standalone, ...):
* *any other relevant information*:
#### What problem are you trying to solve?
We currently have the ability to [set warnings on unknown keys](https://github.com/sideway/joi/issues/2669#issuecomment-985095273) within an object of Joi, but not recursively. It would be nice to have the ability to say "I have an object and if I receive any unknown keys at any depth, I'd like to warn the user." The following technically works, but is not great as it can hide future problems validating joi config.
```js
const wrappedJoiObjectWithUnknownWarnings = (schema?: SchemaMap): ObjectSchema =>
joi.object(schema)
.pattern(/.*/, joiInstance.any().warning(`any.unknown`))
joiInstance.object = wrappedJoiObjectWithUnknownWarnings
```
#### Do you have a new or modified API suggestion to solve the problem?
```js
Joi.object().pattern(/.*/, Joi.any().warning('any.unknown'));
```
Given the single-level warning above, I'm not sure what the best approach here would be. Attaching a `recursive` argument into one of these would make sense, but doesn't feel right in any of the method calls. My initial idea is to add a `Joi.rules` or some other top-level method to set up these types of controls.
Contributor guide
Assessment
This issue has not been assessed yet.