Link and When - Cannot combine object with link
- 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*: v14.15.5
* *module version*: 17.4.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:
#### How can we help?
Hello, thank you for your time. I'm evaluating Joi for replacing AJV, so far so good until I needed to try out one of our recursive schemas. We have modules and templates. Modules has `children` that is a list of resources that can either be a `SubModule` or a `Template`. I was hoping for the following schema to work but I get `Cannot combine object with link` error.
```js
const subModule = Joi.object({
title: Joi.string().required(),
resource: Joi.string().valid("module").required(),
children: Joi.array().items(
Joi.object({
resource: Joi.string().valid("template", "module").required(),
}).when(".resource", {
switch: [
{
is: "module",
then: Joi.link("#subModule"),
},
{
is: "template",
then: template,
},
],
})
),
}).id("subModule");
```
Contributor guide
Research direction
No project files or tests are named. Reproduce the supplied recursive schema in a standalone Node environment using Joi 17.4.0, then inspect how object alternatives, `when`, and `link` are combined. Done means determining whether this schema should be supported and documenting or correcting the resulting behavior with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100