JSON Ref Resolver
Recursively resolves JSON pointers and remote authorities.
Features
- Performant. Hot paths are memoized, only one crawl is needed, and remote authorities are resolved concurrently.
- Caching. Results from remote authorities are cached.
- Immutable. The original object is not changed, and structural sharing is used to only change relevant bits.
- Reference equality. Pointers to the same location will resolve to the same object in memory.
- Flexible. Bring your own readers for http://, file://, mongo://, custom://... etc.
- Reliable. Well tested to handle all sorts of circular reference edge cases.
Usage
All relevant types and options can be found in src/types.ts.
// some example http libraryconst request = ; // fs in node.. in general this library works just fine in the browser thoughconst fs = ; // readers can do anything, so long as they have a read function that returns a promise that resolves to a valueconst httpReader = async { return ; }; // this would obviously only be possible in nodeconst fileReader async readref return fs.readref.toStringtrue; }}; const source = definitions: someOASFile: $ref: './main.oas2.yml#/definitions/user' someMarkdownFile: $ref: 'https://foo.com/intro.md' ; // set our resolver, passing in our scheme -> reader mappingconst resolver = readers: http: httpReader https: httpReader file: fileReader ; const resolved = await resolver; console;// {// definitions: {// someOASFile: // .. whatever data is in the file located in the location definitions.foo in file './main.oas2.yml#/definitions/user'// someMarkdownFile: // .. whatever data is returned from https://foo.com/intro.md// },// }