joi
joi copied to clipboard
ID carries over when Object is extended with append from object that has id defined
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
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