Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/json-schema-tools/reference-resolver
- Owner: json-schema-tools
- License: apache-2.0
- Created: 2020-07-23T22:08:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-26T16:05:57.000Z (4 months ago)
- Last Synced: 2024-11-06T08:47:25.506Z (about 2 months ago)
- Language: TypeScript
- Homepage: https://json-schema-tools.github.io/reference-resolver/
- Size: 1.46 MB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# 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`
```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.