json-schema-tools / traverse

Traverse and optionally mutate a json schema and all it's subschema
https://json-schema-tools.github.io/traverse/
Apache License 2.0
9 stars 3 forks source link

JSON Schema Traverse

CircleCI branch npm GitHub release GitHub commits since latest release

This package exports a method that will traverse a JSON-Schema, calling a "mutation" function for each sub schema found. It is useful for building tools to work with JSON Schemas.

Features

Getting Started

npm install @json-schema-tools/traverse
const traverse = require("@json-schema-tools/traverse").default;
//import traverse from "@json-schema-tools/traverse"

const mySchema = {
  title: "baz",
  type: "object",
  properties: {
    foo: {
      title: "foo",
      type: "array",
      items: { type: "string" }
    },
    bar: {
      title: "bar",
      anyOf: [
        { title: "stringerific", type: "string" },
        { title: "numberoo", type: "number" }
      ]
    }
  }
};

traverse(mySchema, (schemaOrSubschema) => {
  console.log(schemaOrSubschema.title);
});

API Docs

https://json-schema-tools.github.io/traverse/

Features Todo

Contributing

How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.