Closed BrandonNoad closed 1 year ago
Tailored schemas are done deeply, so the problem with this is that you have created your own infinite loop that you need to break out of.
Something like this should work:
Joi.object({
key: Joi.string(),
})
.alter({
patch: (schema) =>
schema.$_getFlag("altered")
? schema
: Joi.alternatives().try(
schema.$_setFlag("altered", true),
Joi.object({ state: Joi.string().required() })
),
})
.tailor("patch");
@Marsup Thanks for the quick response. Your solution resolves the error 🎉 .
Support plan
Context
What are you trying to achieve or the steps to reproduce?
I want to tailor an existing schema to allow it or an alternative schema.
Schema:
Data to Validate:
What was the result you got?
RangeError: Maximum call stack size exceeded
What result did you expect?
Validation Passed
({ state: 'inactive' }
)