Question: Is there a way to create a subschema without some fields of base schema dynamically?
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Context
* *node version*: 12+
* *module version*: 17.6.0
* *environment* (e.g. node, browser, native): node
#### How can we help?
I have a case where I need to create a function which accepts joi schema as the first argument and array of string(object's keys) as the second argument. The main idea here is to return a new schema which consists of a base schema without keys which was mentioned as the second argument. Also, it would be cool to know how to do it with nested schemas.
I have tried different approaches(with different Joi methods), but I did not get the right behavior. Could someone help me to resolve this case?
```js
const schema = Joi.object({
a: Joi.any(),
b: Joi.any()
});
exclude(schema, ['b']) // should return new schema, like Joi.object({ a: Joi.any() })
```
Also, it will be cool to be able do like this:
```js
const schema = Joi.object({
a: Joi.any(),
b: Joi.any(),
c: Joi.object({
d: Joi.any(),
e: Joi.any()
})
});
exclude(schema, ['c.d']) // should return new schema, like
Joi.object({
a: Joi.any(),
b: Joi.any(),
c: Joi.object({
e: Joi.any()
})
});
```
Contributor guide
Assessment
This issue has not been assessed yet.