hapijs / hapijs/joi

"Item cannot come after itself" from ref with a duplicated property name

Open
#2,877 2 comments 0 reactions 0 assignees View on GitHub
bug support
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): yes

#### Context

* *node version*: 14.20.1
* *module version with issue*: 17.7.0
* *last module version without issue*: not tested
* *environment* (e.g. node, browser, native): Node.js
* *used with* (e.g. hapi application, another framework, standalone, ...): Hapi
* *any other relevant information*:

#### What are you trying to achieve or the steps to reproduce?

I'm using a Knex ref with a nested key with a duplicate name.

For example:

```js
const schema = Joi.object({
id: Joi.number().required(),
command: Joi.object({
command: Joi.string().valid('run', 'jump').required(),
params: Joi.alternatives().conditional('command', {
switch: [
{
is: 'run',
then: Joi.object({ howFast: Joi.number().required() }),
},
{
is: 'jump',
then: Joi.object({ howHigh: Joi.number().required() }),
},
],
}),
})
});
```

A sample of a message that complies with this:

```js
{
id: 1,
command: {
command: 'run',
params: { howFast: 1 },
}
}
```

#### What was the result you got?

An error message is thrown within `@hapi/topo`:

> Item cannot come after itself: command

#### What result did you expect?

Usable schema

I'm working around this by renaming one of my property keys.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.