Skip to content

Instantly share code, notes, and snippets.

@myndzi
Last active May 19, 2017 02:17
Show Gist options
  • Save myndzi/87b61c0cb82f5b26d08a5bf405e2341b to your computer and use it in GitHub Desktop.
Save myndzi/87b61c0cb82f5b26d08a5bf405e2341b to your computer and use it in GitHub Desktop.
const Joi = require('joi');
const util = require('util');
const schema = Joi.object().keys({
a: Joi.number().meta('bad a'),
b: Joi.number().meta('bad b')
}).error(errs => {
let obj = { };
errs.forEach(err => {
obj[err.path] = Joi.reach(schema, err.path).describe().meta[0];
});
return JSON.stringify(obj);
});
const value = {
a: 'AAA',
b: "BBB"
};
const result = Joi.validate(value, schema, { abortEarly: false });
console.log(JSON.parse(result.error.message));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment