hapijs / hapijs/joi

Prevent `ref` prefix in error messages of referenced properties

Open
#2,780 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Context

* *node version*: `v14.19.1`
* *module version*: `17.6.0`
* *environment* (e.g. node, browser, native): `node`
* *used with* (e.g. hapi application, another framework, standalone, ...): `express`
* *any other relevant information*:

#### How can we help?

When comparing two properties in a schema using the `ref` function, the error message that's generated includes `ref` as a prefix to the referenced property. Is there any way to stop this behaviour without completely overriding the default error message?

```js
const mySchema = joi.object({
from: joi.number(),
to: joi.number().greater(joi.ref('from'))
});

const payload = {
from: 1,
to: 1
};

const validation = mySchema.validate(payload);

console.log(validation.error.message);

// "to" must be greater than ref:from
```

Ideally, I'd like this message to be:
```js
// "to" must be greater than "from"
```

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.