[Feature request] Prevent parent's tailor option from affecting children tailor options
- 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?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no
#### Context
* *node version*: v12.16.3
* *module version*: v17.2.1
* *environment*: node
* *used with*: standalone
* *any other relevant information*: n/a
#### What problem are you trying to solve?
When using the tailor option both on a child object schema and on the parent schema, the child object will use the tailor option of the parent not it's own.
See below an example using the Joi sandbox:
*Code:*
```javascript
Joi.object({
requiredKey: Joi.string().alter({
create: schema => schema.required(),
update: schema => schema.forbidden()
}),
nested: Joi.object({
forbiddenKey: Joi.string().alter({
create: schema => schema.required(),
update: schema => schema.forbidden()
})
}).tailor("update")
}).tailor("create")
```
```json
{
"requiredKey": "This should pass",
"nested": {
"forbiddenKey": "This should fail"
}
}
```
*Result screenshot:*

#### Do you have a new or modified API suggestion to solve the problem?
The ability to specify options for tailor and create a `freeze` option that will prevent tailor from being changed once it is set.
```javascript
Joi.object({
requiredKey: Joi.string().alter({
create: schema => schema.required(),
update: schema => schema.forbidden()
}),
nested: Joi.object({
forbiddenKey: Joi.string().alter({
create: schema => schema.required(),
update: schema => schema.forbidden()
})
}).tailor("update", { freeze: true })
}).tailor("create")
```
Contributor guide
Assessment
This issue has not been assessed yet.