@stoplight/json-schema-tree
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

@stoplight/json-schema-tree

Use cases

  • json-schema-viewer
  • json-schema-editor
  • masking

Installation

Supported in modern browsers and Node.JS (>=10.18).

# latest stable
yarn add @stoplight/json-schema-tree

Usage

import { SchemaTree, SchemaNodeKind, isRegularNode } from '@stoplight/json-schema-tree';

const tree = new SchemaTree(mySchema);
const ALLOWED_DEPTH = 2;

tree.walker.hookInto('stepIn', node => tree.walker.depth <= ALLOWED_DEPTH); // if flattening is needed, this might need to be tweaked to account for the scenarios where certain nodes can be merged (i.e. arrays)

tree.walker.hookInto('filter', node => {
  return !isRegularNode(node) || node.types === null || !node.types.includes(SchemaNodeKind.Integer); // if a schema property is of type integer, it won't be included in the tree
});

tree.populate();

tree.root; // populated tree

Contributing

  1. Clone repo.
  2. Create / checkout feature/{name}, chore/{name}, or fix/{name} branch.
  3. Install deps: yarn.
  4. Make your changes.
  5. Run tests: yarn test.prod.
  6. Stage relevant files to git.
  7. Commit: yarn commit. NOTE: Commits that don't follow the conventional format will be rejected. yarn commit creates this format for you, or you can put it together manually and then do a regular git commit.
  8. Push: git push.
  9. Open PR targeting the master branch.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.0-beta.10beta
4.0.027,498latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.027,498
3.0.04,247
2.3.1643
2.3.00
2.2.5729
2.2.42
2.2.3109
2.2.2260
2.2.116
2.2.020
2.1.34,150
2.1.20
2.1.17
2.1.00
1.1.0-beta.10
2.0.10
2.0.00
1.1.30
1.1.20
1.1.10
1.0.1-beta.10
1.1.00
1.0.00
1.0.0-beta.60
1.0.0-beta.50
1.0.0-beta.40
1.0.0-beta.30
1.0.0-beta.20
1.0.0-beta.10

Package Sidebar

Install

npm i @stoplight/json-schema-tree

Weekly Downloads

37,681

Version

4.0.0

License

Apache-2.0

Unpacked Size

233 kB

Total Files

43

Last publish

Collaborators

  • stoplight-devops