Détail du package

@json-schema-tools/dereferencer

json-schema-tools321.6kApache-2.01.6.3

Dereference (aka parse refs) from JSON Schemas

readme

JSON Schema Dereferencer

CircleCI branch npm GitHub release GitHub commits since latest release

Otherwise known as a ref parser, this tool will replace json schema using $ref with the underlying reference, returning relevant errors otherwise.

Built using @json-schema-tools/traverse

features

  • minimal dependencies
  • simple & fast
  • cycle detection/handling
  • switchable recusive dereferencing
  • works in node & in browser (isomorphic)
  • handles:
    • relative pointer refs
    • http/https uris
    • local filesystem references
  • configurable
    • optionally de-reference internal references only, keeping it synchronous
    • ignore refs that match a set of patterns
  • extensible
    • dependency injectable fetch and filesystem
    • middleware allows you to easily implement new $ref values.
    • easily add behaviors for custom reference locations
  • option for mutating in place or returning a copy

Getting Started

npm install @json-schema-tools/dereferencer

const JsonSchemaDereferencer = require("@json-schema-tools/dereferencer").default;

const mySchema = {
    type: "object",
    properties: {
      foo: { anyOf: [
        { $ref: "#/properties/bar" },
        { type: "string" }
      ]},
      bar: { $ref: "#/properties/foo" },
      baz: { $ref: "../myschemas/baz.json" },
      jsonSchemaMetaSchema: { $ref: "https://meta.json-schema.tools" }
    },
    additionalProperties: {
        type: "array",
        items: [
            { type: "array", items: { $ref: "#" } },
            { type: "boolean" }
        ]
    }
};

const dereferencer = new JsonSchemaDereferencer(mySchema);

console.log(dereferencer.resolveSync());
console.log(await dereferencer.resolve());

Add custom protocol handling

import JsonSchemaDereferencer from "@json-schema-tools/dereferencer";

const mySchema = {
    type: "object",
    properties: {
      foo: { $ref: "ipfs://39420398420384" }
    }
};

const dereferencer = new JsonSchemaDereferencer(mySchema, {
  protocolHandlerMap: {
    "ipfs": (ref) => Promise.resolve({ type: "string", title: "pretend we got this from ipfs" })
});

console.log(dereferencer.resolveSync());
console.log(await dereferencer.resolve());

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.

changelog

1.6.3 (2024-05-07)

Bug Fixes

1.6.2 (2024-04-09)

Bug Fixes

1.6.1 (2023-02-27)

Bug Fixes

1.6.0 (2023-02-27)

Bug Fixes

  • no longer mutates original schema (9fdc908)
  • update to node 18 (fd5c184)
  • write test to show issue (8df84f4)

Features

  • add an option to toggle mutation of original schema (499657f)

1.5.7 (2022-10-05)

Bug Fixes

  • gh action for linting is broken (14bff9b)
  • lint fix (aebeed8)
  • remove refMap and fix infinite looping case (6c0c5b8)

1.5.6 (2022-10-05)

Bug Fixes

1.5.5 (2022-06-29)

Bug Fixes

  • update dependabot settings (954f058)

1.5.4 (2022-03-18)

Bug Fixes

  • bump version and respect relative path (db93727)
  • ci version bump (7d22690)

1.5.3 (2021-06-24)

Bug Fixes

  • update to new meta-schema (fab77bc)

1.5.2 (2021-06-08)

Bug Fixes

1.5.1 (2021-05-10)

Bug Fixes

1.5.0 (2021-05-10)

Bug Fixes

  • update to latest reference-resolver (a238336)

Features

  • add custom protocol handling (593b400)

1.4.2 (2021-05-10)

Bug Fixes

1.4.1 (2021-05-10)

Bug Fixes

1.4.0 (2020-11-10)

Bug Fixes

Features

  • refactor into something that will work for all the cases (5ce57c0)

1.3.1 (2020-11-04)

Bug Fixes

  • add more tests and implement fix (0f48a69)
  • failing test for nested oneOf ref (e6ad83c)

1.3.0 (2020-11-02)

Features

  • handle case with root schema as ref (1cd02fc)

1.2.14 (2020-10-28)

Bug Fixes

  • update ref resolver for browser build (e4e062f)

1.2.13 (2020-10-27)

Bug Fixes

1.2.12 (2020-10-27)

Bug Fixes

  • remove unused browser field in package.json (525d82b)

1.2.11 (2020-10-23)

Bug Fixes

1.2.10 (2020-10-23)

Bug Fixes

1.2.9 (2020-10-23)

Bug Fixes

1.2.8 (2020-10-23)

Bug Fixes

1.2.7 (2020-10-23)

Bug Fixes

  • add eslint dependency and workflow (8ac862b)
  • setup eslint properly (61cdec3)

1.2.6 (2020-10-17)

Bug Fixes

  • update reference resolver to latest (11e2862)

1.2.5 (2020-10-17)

Bug Fixes

1.2.4 (2020-10-17)

Bug Fixes

  • update meta schema to latest (b5b073b)

1.2.3 (2020-10-17)

Bug Fixes

  • add back refCache for cycle handling (999f800)
  • bump typescript and node typings (12ddcf8)
  • re-add jest types (5b391e7)
  • regen package-lock (df17cfc)
  • use reference resolver package (2ab425d)
  • use safe stringify (0509f87)

1.2.2 (2020-09-09)

Bug Fixes

  • fs.constants updated for web (0d3518e), closes #61

1.2.1 (2020-07-28)

Bug Fixes

1.2.0 (2020-07-22)

Features

  • isomorphic browser n node support (0ef22b4)

1.1.0 (2020-07-21)

Bug Fixes

  • remove hold (df2f3bb)
  • update package json meta a little bit (cb257fe)

Features

  • update to new meta schema and traverse (b42fb4a)

1.0.15 (2020-07-20)

Bug Fixes

1.0.14 (2020-07-15)

Bug Fixes

1.0.13 (2020-07-07)

Bug Fixes

  • remove definitions key after dereffing (ed43c3f)

1.0.12 (2020-07-07)

Bug Fixes

1.0.11 (2020-07-07)

Bug Fixes

  • update traverse with cycle fix (2371305)

1.0.10 (2020-07-06)

Bug Fixes

1.0.9 (2020-07-06)

Bug Fixes

  • add test that infinite loops. bed time fuck this shit (d269fe5)
  • pre-refactoring (cf25929)
  • remove commented out garbage (b2ede0a)
  • tests passing but logs after tests finish still somehow (06f2a07)

1.0.8 (2020-07-03)

Bug Fixes

1.0.7 (2020-07-01)

Bug Fixes

1.0.6 (2020-07-01)

Bug Fixes

1.0.5 (2020-06-30)

Bug Fixes

1.0.4 (2020-06-30)

Bug Fixes

1.0.3 (2020-06-27)

Bug Fixes

1.0.2 (2020-06-27)

Bug Fixes

1.0.1 (2020-06-26)

Bug Fixes

  • add funding (ffda6d9)
  • put hold in parallel with test and build (479ed2f)

1.0.0 (2020-06-26)

Bug Fixes

Features