hapijs / joi

The most powerful data validation library for JS
Other
20.95k stars 1.51k forks source link

Passing meta data from schema to validation result #2939

Open minhnq013 opened 1 year ago

minhnq013 commented 1 year ago

Support plan

Context

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']