-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
Support plan
- which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
- is this issue currently blocking your project? (yes/no): No
- is this issue affecting a production system? (yes/no): No
Context
- node version: 12-13
- module version: 17.1.0
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...):
- any other relevant information:
What problem are you trying to solve?
Currently generated error messages contain [ref:...] when used with references, while this is reasonably useful when dealing with local refs (since the values are usually provided by the client), they are less useful when dealing with references that use context.
Use case:
I am providing some dynamic configuration via $.app.request.... and I'd rather display the value of the ref than the name of the ref in the validation messages as showing the ref name would expose internal information which the client has no use for.
const a = j.object({ a: j.valid(j.ref('$test')).required() }).validate({ a: 2 }, { context: { test: [3] } })Current:
{
value: { a: 2 },
error: [Error [ValidationError]: "a" must be [ref:global:test]] {
_original: { a: 2 },
details: [ [Object] ]
}
}
Desired:
{
value: { a: 2 },
error: [Error [ValidationError]: "a" must be 3] {
_original: { a: 2 },
details: [ [Object] ]
}
}
Do you have a new or modified API suggestion to solve the problem?
I have 2 proposed solutions:
- Allow passing an option
resolveRefValuesInMessages(name debatable) in.validate/assertcall. - Allow passing an option
resolveValuesInMessagein the 2nd param of.in()and.ref().
eg.
const a = j.object({
a: j.valid(j.ref('$test', { resolveValuesInMessage: true })).required()
}).validate({ a: 2 }, { context: { test: [3] } });OR
const a = j.object({
a: j.valid(j.ref('$test')).required()
}).validate({ a: 2 }, { context: { test: [3] }, resolveRefValuesInMessages: true });Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement