1.2.5 • Published 2 years ago

@json-schema-tools/reference-resolver v1.2.5

Weekly downloads
426
License
Apache-2.0
Repository
github
Last release
2 years ago

JSON Schema Reference Resolver

Takes a $ref string and a root object, and returns the referenced value.

Works in browser & in node (file system refs ignored in browser).

Easily add support for your own protocols.

Getting Started

npm install @json-schema-tools/reference-resolver

import refRes from "@json-schema-tools/reference-resolver";

refRes.resolve("#/properties/foo", { properties: { foo: true } }); // returns true
refRes.resolve("https://foo.com/"); // returns what ever json foo.com returns
refRef.resolve("../my-object.json"); // you get teh idea

Adding custom protocol handlers

import referenceResolver from "@json-schema-tools/reference-resolver";
import JSONSchema from "@json-schema-tools/meta-schema";

referenceResolver.protocolHandlerMap.ipfs = (uri) => {
   const pretendItsFetchedFromIpfs = {
     title: "foo",
     type: "string",
   } as JSONSchema;
   return Promise.resolve(fetchedFromIpfs);
};

referenceResolver.protocolHandlerMap["customprotocol"] = (uri) => {
   return Promise.resolve({
     type: "string",
     title: uri.replace("customprotocol://", ""),
   });
};

referenceResolver.resolve("ipfs://80088008800880088008");
referenceResolver.resolve("customprotocol://foobar");

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.

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago