Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/json-schema-tools/reference-resolver

takes $ref strings and a root object, returns the resolved value of the reference
https://github.com/json-schema-tools/reference-resolver

Last synced: about 1 month ago
JSON representation

takes $ref strings and a root object, returns the resolved value of the reference

Awesome Lists containing this project

README

        

# JSON Schema Reference Resolver


CircleCI branch

npm
GitHub release
GitHub commits since latest release

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`

```typescript
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

```typescript
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](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification.