ajv-error-tree

0.0.5 • Public • Published

ajv-error-tree

Convert a list of ajv errors into the logical tree it was always meant to be.

Requirement: ajv@8.x.x.

Example:

const Ajv = require("ajv");
const YAML = require("yaml");
const { asTree } = require("treeify");
const {
  structureAJVErrorArray,
  summarizeAJVErrorTree,
} = require("ajv-error-tree");
const ajv = new Ajv({ verbose: true });
const validate = ajv.compile({
  type: "array",
  items: {
    anyOf: [
      {type: "number"},
      {type: "boolean"}
    ]
  }
});
console.assert(!validate([123, true, "foo"]));
const tree1 = structureAJVErrorArray(validate.errors);
const tree2 = summarizeAJVErrorTree(tree1);
console.log(asTree(tree2, true));
// ├─ .: /items/anyOf >> /2 must match a schema in anyOf
// └─ +
//    ├─ 0: /items/anyOf/0/type >> /2 must be number
//    └─ 1: /items/anyOf/1/type >> /2 must be boolean

See sample for another example.

/ajv-error-tree/

    Package Sidebar

    Install

    npm i ajv-error-tree

    Weekly Downloads

    231

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    5.25 kB

    Total Files

    4

    Last publish

    Collaborators

    • lachrist