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

@apidevtools/json-schema-ref-parser

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apidevtools/json-schema-ref-parser - npm Package Compare versions

Comparing version 9.1.1 to 10.0.0

cjs/bundle.js

10

lib/bundle.js

@@ -1,9 +0,7 @@

"use strict";
import $Ref from "./ref.js";
import Pointer from "./pointer.js";
import * as url from "./util/url.js";
const $Ref = require("./ref");
const Pointer = require("./pointer");
const url = require("./util/url");
export default bundle;
module.exports = bundle;
/**

@@ -10,0 +8,0 @@ * Bundles all external JSON references into the main JSON schema, thus resulting in a schema that

12

lib/dereference.js

@@ -1,10 +0,8 @@

"use strict";
import $Ref from "./ref.js";
import Pointer from "./pointer.js";
import { ono } from "@jsdevtools/ono";
import * as url from "./util/url.js";
const $Ref = require("./ref");
const Pointer = require("./pointer");
const { ono } = require("@jsdevtools/ono");
const url = require("./util/url");
export default dereference;
module.exports = dereference;
/**

@@ -11,0 +9,0 @@ * Crawls the JSON schema, finds all JSON references, and dereferences them.

/* eslint-disable no-unused-vars */
"use strict";
import $Refs from "./refs.js";
import _parse from "./parse.js";
import normalizeArgs from "./normalize-args.js";
import resolveExternal from "./resolve-external.js";
import _bundle from "./bundle.js";
import _dereference from "./dereference.js";
import * as url from "./util/url.js";
import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } from "./util/errors.js";
import maybe from "call-me-maybe";
import { ono } from "@jsdevtools/ono";
const $Refs = require("./refs");
const _parse = require("./parse");
const normalizeArgs = require("./normalize-args");
const resolveExternal = require("./resolve-external");
const _bundle = require("./bundle");
const _dereference = require("./dereference");
const url = require("./util/url");
const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } = require("./util/errors");
const maybe = require("call-me-maybe");
const { ono } = require("@jsdevtools/ono");
export default $RefParser;
export { JSONParserError };
export { InvalidPointerError };
export { MissingPointerError };
export { ResolverError };
export { ParserError };
export { UnmatchedParserError };
export { UnmatchedResolverError };
module.exports = $RefParser;
module.exports.default = $RefParser;
module.exports.JSONParserError = JSONParserError;
module.exports.InvalidPointerError = InvalidPointerError;
module.exports.MissingPointerError = MissingPointerError;
module.exports.ResolverError = ResolverError;
module.exports.ParserError = ParserError;
module.exports.UnmatchedParserError = UnmatchedParserError;
module.exports.UnmatchedResolverError = UnmatchedResolverError;
/**

@@ -284,1 +281,11 @@ * This class parses a JSON schema, builds a map of its JSON references and their resolved values,

}
export const parse = $RefParser.parse.bind($RefParser);
export const resolve = $RefParser.resolve.bind($RefParser);
export const bundle = $RefParser.bundle.bind($RefParser);
export const dereference = $RefParser.dereference.bind($RefParser);
// CommonJS default export hack
if (typeof module === "object" && typeof module.exports === "object") {
module.exports = Object.assign(module.exports.default, module.exports);
}

@@ -1,7 +0,5 @@

"use strict";
import Options from "./options.js";
const Options = require("./options");
export default normalizeArgs;
module.exports = normalizeArgs;
/**

@@ -8,0 +6,0 @@ * Normalizes the given arguments, accounting for optional args.

/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
"use strict";
import jsonParser from "./parsers/json.js";
import yamlParser from "./parsers/yaml.js";
import textParser from "./parsers/text.js";
import binaryParser from "./parsers/binary.js";
import fileResolver from "./resolvers/file.js";
import httpResolver from "./resolvers/http.js";
const jsonParser = require("./parsers/json");
const yamlParser = require("./parsers/yaml");
const textParser = require("./parsers/text");
const binaryParser = require("./parsers/binary");
const fileResolver = require("./resolvers/file");
const httpResolver = require("./resolvers/http");
export default $RefParserOptions;
module.exports = $RefParserOptions;
/**

@@ -14,0 +12,0 @@ * Options that determine how JSON schemas are parsed, resolved, and dereferenced.

@@ -1,10 +0,8 @@

"use strict";
import { ono } from "@jsdevtools/ono";
import * as url from "./util/url.js";
import * as plugins from "./util/plugins.js";
import { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } from "./util/errors.js";
const { ono } = require("@jsdevtools/ono");
const url = require("./util/url");
const plugins = require("./util/plugins");
const { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
export default parse;
module.exports = parse;
/**

@@ -11,0 +9,0 @@ * Reads and parses the specified file path or URL.

@@ -1,6 +0,4 @@

"use strict";
let BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
module.exports = {
export default {
/**

@@ -7,0 +5,0 @@ * The order that this parser will run, in relation to other parsers.

@@ -1,6 +0,4 @@

"use strict";
import { ParserError } from "../util/errors.js";
const { ParserError } = require("../util/errors");
module.exports = {
export default {
/**

@@ -7,0 +5,0 @@ * The order that this parser will run, in relation to other parsers.

@@ -1,8 +0,6 @@

"use strict";
import { ParserError } from "../util/errors.js";
const { ParserError } = require("../util/errors");
let TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
module.exports = {
export default {
/**

@@ -9,0 +7,0 @@ * The order that this parser will run, in relation to other parsers.

@@ -1,8 +0,6 @@

"use strict";
import { ParserError } from "../util/errors.js";
import yaml from "js-yaml";
import { JSON_SCHEMA } from "js-yaml";
const { ParserError } = require("../util/errors");
const yaml = require("js-yaml");
const { JSON_SCHEMA } = require("js-yaml");
module.exports = {
export default {
/**

@@ -9,0 +7,0 @@ * The order that this parser will run, in relation to other parsers.

@@ -1,8 +0,6 @@

"use strict";
export default Pointer;
module.exports = Pointer;
const $Ref = require("./ref");
const url = require("./util/url");
const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
import $Ref from "./ref.js";
import * as url from "./util/url.js";
import { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } from "./util/errors.js";
const slashes = /\//g;

@@ -9,0 +7,0 @@ const tildes = /~/g;

@@ -1,9 +0,7 @@

"use strict";
export default $Ref;
module.exports = $Ref;
import Pointer from "./pointer.js";
import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js";
import { safePointerToPath, stripHash, getHash } from "./util/url.js";
const Pointer = require("./pointer");
const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors");
const { safePointerToPath, stripHash, getHash } = require("./util/url");
/**

@@ -10,0 +8,0 @@ * This class represents a single JSON reference and its resolved value.

@@ -1,16 +0,12 @@

"use strict";
import { ono } from "@jsdevtools/ono";
import $Ref from "./ref.js";
import * as url from "./util/url.js";
const { ono } = require("@jsdevtools/ono");
const $Ref = require("./ref");
const url = require("./util/url");
const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined);
const getPathFromOs = filePath => isWindows ? filePath.replace(/\\/g, "/") : filePath;
module.exports = $Refs;
/**
* This class is a map of JSON references and their resolved values.
*/
function $Refs () {
export default function $Refs () {
/**

@@ -17,0 +13,0 @@ * Indicates whether the schema contains any circular references.

@@ -1,11 +0,9 @@

"use strict";
import $Ref from "./ref.js";
import Pointer from "./pointer.js";
import parse from "./parse.js";
import * as url from "./util/url.js";
import { isHandledError } from "./util/errors.js";
const $Ref = require("./ref");
const Pointer = require("./pointer");
const parse = require("./parse");
const url = require("./util/url");
const { isHandledError } = require("./util/errors");
export default resolveExternal;
module.exports = resolveExternal;
/**

@@ -12,0 +10,0 @@ * Crawls the JSON schema, finds all external JSON references, and resolves their values.

@@ -1,8 +0,7 @@

"use strict";
const fs = require("fs");
const { ono } = require("@jsdevtools/ono");
const url = require("../util/url");
const { ResolverError } = require("../util/errors");
import fs from "fs";
import { ono } from "@jsdevtools/ono";
import * as url from "../util/url.js";
import { ResolverError } from "../util/errors.js";
module.exports = {
export default {
/**

@@ -9,0 +8,0 @@ * The order that this resolver will run, in relation to other resolvers.

@@ -1,8 +0,6 @@

"use strict";
import { ono } from "@jsdevtools/ono";
import * as url from "../util/url.js";
import { ResolverError } from "../util/errors.js";
const { ono } = require("@jsdevtools/ono");
const url = require("../util/url");
const { ResolverError } = require("../util/errors");
module.exports = {
export default {
/**

@@ -9,0 +7,0 @@ * The order that this resolver will run, in relation to other resolvers.

@@ -1,8 +0,6 @@

"use strict";
import { Ono } from "@jsdevtools/ono";
const { Ono } = require("@jsdevtools/ono");
import { stripHash, toFileSystemPath } from "./url.js";
const { stripHash, toFileSystemPath } = require("./url");
const JSONParserError = exports.JSONParserError = class JSONParserError extends Error {
export const JSONParserError = class JSONParserError extends Error {
constructor (message, source) {

@@ -26,3 +24,3 @@ super();

const JSONParserErrorGroup = exports.JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
export const JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
constructor (parser) {

@@ -56,3 +54,3 @@ super();

const ParserError = exports.ParserError = class ParserError extends JSONParserError {
export const ParserError = class ParserError extends JSONParserError {
constructor (message, source) {

@@ -67,3 +65,3 @@ super(`Error parsing ${source}: ${message}`, source);

const UnmatchedParserError = exports.UnmatchedParserError = class UnmatchedParserError extends JSONParserError {
export const UnmatchedParserError = class UnmatchedParserError extends JSONParserError {
constructor (source) {

@@ -78,3 +76,3 @@ super(`Could not find parser for "${source}"`, source);

const ResolverError = exports.ResolverError = class ResolverError extends JSONParserError {
export const ResolverError = class ResolverError extends JSONParserError {
constructor (ex, source) {

@@ -93,3 +91,3 @@ super(ex.message || `Error reading file "${source}"`, source);

const UnmatchedResolverError = exports.UnmatchedResolverError = class UnmatchedResolverError extends JSONParserError {
export const UnmatchedResolverError = class UnmatchedResolverError extends JSONParserError {
constructor (source) {

@@ -104,3 +102,3 @@ super(`Could not find resolver for "${source}"`, source);

const MissingPointerError = exports.MissingPointerError = class MissingPointerError extends JSONParserError {
export const MissingPointerError = class MissingPointerError extends JSONParserError {
constructor (token, path) {

@@ -115,3 +113,3 @@ super(`Token "${token}" does not exist.`, stripHash(path));

const InvalidPointerError = exports.InvalidPointerError = class InvalidPointerError extends JSONParserError {
export const InvalidPointerError = class InvalidPointerError extends JSONParserError {
constructor (pointer, path) {

@@ -133,7 +131,7 @@ super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path));

exports.isHandledError = function (err) {
export function isHandledError (err) {
return err instanceof JSONParserError || err instanceof JSONParserErrorGroup;
};
}
exports.normalizeError = function (err) {
export function normalizeError (err) {
if (err.path === null) {

@@ -144,2 +142,2 @@ err.path = [];

return err;
};
}

@@ -1,3 +0,1 @@

"use strict";
/**

@@ -10,3 +8,3 @@ * Returns the given plugins as an array, rather than an object map.

*/
exports.all = function (plugins) {
export function all (plugins) {
return Object.keys(plugins)

@@ -20,3 +18,3 @@ .filter((key) => {

});
};
}

@@ -31,3 +29,3 @@ /**

*/
exports.filter = function (plugins, method, file) {
export function filter (plugins, method, file) {
return plugins

@@ -37,3 +35,3 @@ .filter((plugin) => {

});
};
}

@@ -46,3 +44,3 @@ /**

*/
exports.sort = function (plugins) {
export function sort (plugins) {
for (let plugin of plugins) {

@@ -53,3 +51,3 @@ plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;

return plugins.sort((a, b) => { return a.order - b.order; });
};
}

@@ -69,3 +67,3 @@ /**

*/
exports.run = function (plugins, method, file, $refs) {
export function run (plugins, method, file, $refs) {
let plugin, lastError, index = 0;

@@ -129,3 +127,3 @@

}));
};
}

@@ -132,0 +130,0 @@ /**

@@ -1,10 +0,6 @@

"use strict";
import projectDir from "./projectDir.cjs";
const nodePath = require("path");
const projectDir = nodePath.resolve(__dirname, "..", "..");
let isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined),
forwardSlashPattern = /\//g,
protocolPattern = /^(\w{2,}):\/\//i,
url = module.exports,
jsonPointerSlash = /~1/g,

@@ -28,3 +24,3 @@ jsonPointerTilde = /~0/g;

exports.parse = (u) => new URL(u);
export const parse = (u) => new URL(u);

@@ -36,3 +32,3 @@ /**

*/
exports.resolve = function resolve (from, to) {
export function resolve (from, to) {
let resolvedUrl = new URL(to, new URL(from, "resolve://"));

@@ -45,3 +41,3 @@ if (resolvedUrl.protocol === "resolve:") {

return resolvedUrl.toString();
};
}

@@ -53,3 +49,3 @@ /**

*/
exports.cwd = function cwd () {
export function cwd () {
if (typeof window !== "undefined") {

@@ -68,3 +64,3 @@ return location.href;

}
};
}

@@ -77,3 +73,3 @@ /**

*/
exports.getProtocol = function getProtocol (path) {
export function getProtocol (path) {
let match = protocolPattern.exec(path);

@@ -83,3 +79,3 @@ if (match) {

}
};
}

@@ -93,9 +89,9 @@ /**

*/
exports.getExtension = function getExtension (path) {
export function getExtension (path) {
let lastDot = path.lastIndexOf(".");
if (lastDot >= 0) {
return url.stripQuery(path.substr(lastDot).toLowerCase());
return stripQuery(path.substr(lastDot).toLowerCase());
}
return "";
};
}

@@ -108,3 +104,3 @@ /**

*/
exports.stripQuery = function stripQuery (path) {
export function stripQuery (path) {
let queryIndex = path.indexOf("?");

@@ -115,3 +111,3 @@ if (queryIndex >= 0) {

return path;
};
}

@@ -125,3 +121,3 @@ /**

*/
exports.getHash = function getHash (path) {
export function getHash (path) {
let hashIndex = path.indexOf("#");

@@ -132,3 +128,3 @@ if (hashIndex >= 0) {

return "#";
};
}

@@ -141,3 +137,3 @@ /**

*/
exports.stripHash = function stripHash (path) {
export function stripHash (path) {
let hashIndex = path.indexOf("#");

@@ -148,3 +144,3 @@ if (hashIndex >= 0) {

return path;
};
}

@@ -157,4 +153,4 @@ /**

*/
exports.isHttp = function isHttp (path) {
let protocol = url.getProtocol(path);
export function isHttp (path) {
let protocol = getProtocol(path);
if (protocol === "http" || protocol === "https") {

@@ -171,3 +167,3 @@ return true;

}
};
}

@@ -181,3 +177,3 @@ /**

*/
exports.isFileSystemPath = function isFileSystemPath (path) {
export function isFileSystemPath (path) {
if (process.browser) {

@@ -189,5 +185,5 @@ // We're running in a browser, so assume that all paths are URLs.

let protocol = url.getProtocol(path);
let protocol = getProtocol(path);
return protocol === undefined || protocol === "file";
};
}

@@ -210,3 +206,3 @@ /**

*/
exports.fromFileSystemPath = function fromFileSystemPath (path) {
export function fromFileSystemPath (path) {
// Step 1: On Windows, replace backslashes with forward slashes,

@@ -236,3 +232,3 @@ // rather than encoding them as "%5C"

return path;
};
}

@@ -246,3 +242,3 @@ /**

*/
exports.toFileSystemPath = function toFileSystemPath (path, keepFileProtocol) {
export function toFileSystemPath (path, keepFileProtocol) {
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.

@@ -295,3 +291,3 @@ path = decodeURI(path);

return path;
};
}

@@ -304,3 +300,3 @@ /**

*/
exports.safePointerToPath = function safePointerToPath (pointer) {
export function safePointerToPath (pointer) {
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {

@@ -318,2 +314,2 @@ return [];

});
};
}
{
"name": "@apidevtools/json-schema-ref-parser",
"version": "9.1.1",
"version": "10.0.0",
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",

@@ -42,2 +42,7 @@ "keywords": [

"typings": "lib/index.d.ts",
"exports": {
"types": "./lib/index.d.ts",
"require": "./cjs/index.js",
"default": "./lib/index.js"
},
"browser": {

@@ -50,14 +55,16 @@ "fs": false

"files": [
"lib"
"lib",
"cjs"
],
"type": "module",
"scripts": {
"build": "cp LICENSE *.md dist",
"clean": "shx rm -rf .nyc_output coverage",
"build": "swc ./lib/*.js -d ./cjs && swc ./lib/**/*.js -d ./cjs && copyfiles ./lib/**/*.cjs -u 1 ./cjs && node ./scripts/writeCJSPackageJSON.cjs",
"clean": "shx rm -rf coverage cjs",
"lint": "eslint lib test/fixtures test/specs",
"test": "npm run test:node && npm run test:typescript && npm run test:browser && npm run lint",
"test:node": "mocha",
"test:browser": "cross-env NODE_OPTIONS=--openssl-legacy-provider karma start --single-run",
"test:browser": "cross-env NODE_OPTIONS=--openssl-legacy-provider karma start karma.conf.cjs --single-run",
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts",
"coverage": "npm run coverage:node && npm run coverage:browser",
"coverage:node": "nyc node_modules/mocha/bin/mocha",
"coverage:node": "c8 node_modules/mocha/bin/mocha",
"coverage:browser": "npm run test:browser -- --coverage",

@@ -72,6 +79,10 @@ "upgrade": "npm-check -u && npm audit fix"

"@jsdevtools/karma-config": "^3.1.7",
"@swc/cli": "^0.1.59",
"@swc/core": "^1.3.25",
"@types/node": "^14.14.21",
"c8": "^7.12.0",
"chai": "^4.2.0",
"chai-subset": "^1.6.0",
"chokidar": "^3.5.3",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",

@@ -85,4 +96,2 @@ "eslint": "^7.18.0",

"npm-check": "^5.9.0",
"nyc": "^15.0.1",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"shx": "^0.3.2",

@@ -104,11 +113,2 @@ "typescript": "^4.0.5"

"@semantic-release/release-notes-generator",
[
"semantic-release-plugin-update-version-in-files",
{
"files": [
"dist/package.json"
],
"placeholder": "X.X.X"
}
],
"@semantic-release/npm",

@@ -115,0 +115,0 @@ "@semantic-release/github"

# JSON Schema $Ref Parser
_**This package needs [a new maintainer](https://github.com/APIDevTools/json-schema-ref-parser/issues/285) or at least some contributors, or a decent number of sponsors so I can hire contractors to do the work. For more information [please read this article](https://phil.tech/2022/bundling-openapi-with-javascript/). I'll mark the repo as read-only and unmaintained on January 15th 2023 along with a bunch of other @apidevtools packages like swagger-parser, so I can focus on scaling up my [reforestation charity](https://protect.earth/) instead of burning myself out trying to maintain a whole load of OSS projects I don't use in my vanishingly small spare time.** - [Phil Sturgeon](https://github.com/philsturgeon)_
_**This package needs [a new maintainer](https://github.com/APIDevTools/json-schema-ref-parser/issues/285) or at least some contributors. For more information [please read this article](https://phil.tech/2022/bundling-openapi-with-javascript/). As of v10.0.0 I am no longer spending any time working on this tool, so I can focus on scaling up my [reforestation charity](https://protect.earth/) instead of burning myself out trying to maintain a whole load of OSS projects I don't use in my vanishingly small spare time. Get in touch if you'd like to take over.** - [Phil Sturgeon](https://github.com/philsturgeon)_

@@ -11,10 +11,5 @@ #### Parse, Resolve, and Dereference JSON Schema $ref pointers

[![npm](https://img.shields.io/npm/v/@apidevtools/json-schema-ref-parser.svg)](https://www.npmjs.com/package/@apidevtools/json-schema-ref-parser)
[![Dependencies](https://david-dm.org/APIDevTools/json-schema-ref-parser.svg)](https://david-dm.org/APIDevTools/json-schema-ref-parser)
[![License](https://img.shields.io/npm/l/@apidevtools/json-schema-ref-parser.svg)](LICENSE)
[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser)
[![OS and Browser Compatibility](https://apitools.dev/img/badges/ci-badges-with-ie.svg)](https://github.com/APIDevTools/json-schema-ref-parser/actions)
The Problem:

@@ -21,0 +16,0 @@ --------------------------

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