joi
joi copied to clipboard
Passing meta data from schema to validation result
Support plan
- is this issue currently blocking your project? yes:
- is this issue affecting a production system? no:
Context
- node version: v16.14.0
- module version: 17.6.0
- environment browser
- used with (e.g. hapi application, another framework, standalone, ...):
- any other relevant information:
How can we help?
Hi team, I would like to tag a schema with some metadata that will be included in any validation result of that schema or its children schema. Is this possible with the current state of Joi?
I think it is similar to artifact
but also work for failed rule.
const schema = Joi.object({
name: Joi.string().required(),
})
.schemaTag('special-tag')
const result = schema.validate(
{ gaga: 'gaga' }
)
console.log(result.details.map(detail => detail.schemaTag))) // ['special-tag']