ID carries over when Object is extended with append from object that has id defined
- 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.5.0
* *module version with issue*: 17.4.2
* *last module version without issue*: unknown
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:
#### What are you trying to achieve or the steps to reproduce?
When a base object schema that has an id is extended using the `append` method, the extended schema retains the id from the base schema. Not entirely sure if this is a bug or a design choice but it caused unexpected behavior for me while implementing a mutually recursive schema using Joi.link, and seems unintentional or at least in need of documentation.
I'm currently working around this behavior by adding an `id` to the extended schema to override the id copied from the base
Minimal reproduction steps
```js
import Joi from "joi"
const Base = Joi.object({Base: true}).id("Base")
const Extended = Base.append({Extended:true})
console.log(`Base ID is ${Base.$_getFlag('id')}`)
console.log(`Extended ID is ${Extended.$_getFlag('id')}`)
```
#### What was the result you got?
```
Base ID is Base
Extended ID is Base
```
#### What result did you expect?
```
Base ID is Base
Extended ID is undefined
```
Contributor guide
Assessment
This issue has not been assessed yet.