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

@stoplight/json-ref-resolver

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/json-ref-resolver

Recursively resolve JSON pointers and remote authorities.

  • 3.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @stoplight/json-ref-resolver?

@stoplight/json-ref-resolver is a utility for resolving JSON references ($ref) in JSON documents. It helps in dereferencing and bundling JSON schemas or other JSON documents that contain references to other documents or internal references.

What are @stoplight/json-ref-resolver's main functionalities?

Dereferencing JSON References

This feature allows you to resolve internal JSON references within a document. The example shows how a reference to '#/bar' is resolved to the actual content of 'bar'.

const { resolve } = require('@stoplight/json-ref-resolver');

const document = {
  "foo": { "$ref": "#/bar" },
  "bar": { "baz": 123 }
};

resolve(document).then(result => {
  console.log(result);
  // Output: { foo: { baz: 123 }, bar: { baz: 123 } }
});

Resolving External JSON References

This feature allows you to resolve external JSON references by fetching the referenced document from a URL. The example shows how a reference to an external URL is resolved.

const { resolve } = require('@stoplight/json-ref-resolver');

const document = {
  "foo": { "$ref": "http://example.com/bar.json" }
};

resolve(document).then(result => {
  console.log(result);
  // Output will depend on the content of http://example.com/bar.json
});

Custom Resolvers

This feature allows you to define custom resolvers for handling specific types of references. The example shows how to create a custom resolver for a 'custom://' scheme.

const { resolve } = require('@stoplight/json-ref-resolver');

const customResolver = {
  canRead: (file) => file.url.startsWith('custom://'),
  read: (file) => Promise.resolve({ custom: 'data' })
};

const document = {
  "foo": { "$ref": "custom://example" }
};

resolve(document, { resolvers: [customResolver] }).then(result => {
  console.log(result);
  // Output: { foo: { custom: 'data' } }
});

Other packages similar to @stoplight/json-ref-resolver

Keywords

FAQs

Package last updated on 13 Jul 2023

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