Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-ref-resolver

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-ref-resolver

Recursively resolves JSON pointers and remote authorities.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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 library
const request = require('request');

// fs in node.. in general this library works just fine in the browser though
const fs = require('fs');

// readers can do anything, so long as they have a read function that returns a promise that resolves to a value
const httpReader = {
  async read(ref) {
    return request(ref.toString());
  },
};

// this would obviously only be possible in node
const fileReader {
  async read(ref) {
    return fs.read(ref.toString(true));
  },
};

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 mapping
const resolver = new Resolver({
  readers: {
    http: httpReader,
    https: httpReader,
    file: fileReader,
  },
});

const resolved = await resolver.resolve(source);

console.log(resolved.result);
// {
//   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
//   },
// }

FAQs

Package last updated on 24 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc