Socket
Socket
Sign inDemoInstall

@apidevtools/json-schema-ref-parser

Package Overview
Dependencies
Maintainers
2
Versions
42
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.0 to 9.1.1

2

lib/bundle.js

@@ -138,3 +138,3 @@ "use strict";

// Recursively crawl the resolved value
if (!existingEntry) {
if (!existingEntry || external) {
crawl(pointer.value, null, pointer.path, pathFromRoot, indirections + 1, inventory, $refs, options);

@@ -141,0 +141,0 @@ }

@@ -74,2 +74,5 @@ "use strict";

obj[key] = dereferenced.value;
if (options.dereference.onDereference) {
options.dereference.onDereference(value.$ref, obj[key]);
}
}

@@ -76,0 +79,0 @@ }

@@ -1,2 +0,2 @@

import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema";
import { JSONSchema4, JSONSchema4Object, JSONSchema4Type, JSONSchema6, JSONSchema6Object, JSONSchema6Type, JSONSchema7, JSONSchema7Object, JSONSchema7Type } from "json-schema";

@@ -177,2 +177,3 @@ export = $RefParser;

export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any;

@@ -242,2 +243,10 @@ export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;

excludedPathMatcher?(path: string): boolean;
/**
* Callback invoked during dereferencing.
*
* @argument {string} path The path being dereferenced (ie. the `$ref` string).
* @argument {JSONSchemaObject} object The JSON-Schema that the `$ref` resolved to.
*/
onDereference(path: string, value: JSONSchemaObject): void;
};

@@ -244,0 +253,0 @@ }

@@ -7,2 +7,5 @@ "use strict";

const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined);
const getPathFromOs = filePath => isWindows ? filePath.replace(/\\/g, "/") : filePath;
module.exports = $Refs;

@@ -48,3 +51,3 @@

return paths.map((path) => {
return path.decoded;
return getPathFromOs(path.decoded);
});

@@ -63,3 +66,3 @@ };

return paths.reduce((obj, path) => {
obj[path.decoded] = $refs[path.encoded].value;
obj[getPathFromOs(path.decoded)] = $refs[path.encoded].value;
return obj;

@@ -66,0 +69,0 @@ }, {});

"use strict";
const http = require("http");
const https = require("https");
const { ono } = require("@jsdevtools/ono");

@@ -78,3 +76,3 @@ const url = require("../util/url");

if (process.browser && !u.protocol) {
if (typeof window !== "undefined" && !u.protocol) {
// Use the protocol of the current page

@@ -99,34 +97,32 @@ u.protocol = url.parse(location.href).protocol;

function download (u, httpOptions, redirects) {
return new Promise(((resolve, reject) => {
u = url.parse(u);
redirects = redirects || [];
redirects.push(u.href);
u = url.parse(u);
redirects = redirects || [];
redirects.push(u.href);
get(u, httpOptions)
.then((res) => {
if (res.statusCode >= 400) {
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.statusCode}`);
return get(u, httpOptions)
.then((res) => {
if (res.status >= 400) {
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.status}`);
}
else if (res.status >= 300) {
if (redirects.length > httpOptions.redirects) {
throw new ResolverError(ono({ status: res.status },
`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`));
}
else if (res.statusCode >= 300) {
if (redirects.length > httpOptions.redirects) {
reject(new ResolverError(ono({ status: res.statusCode },
`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`)));
}
else if (!res.headers.location) {
throw ono({ status: res.statusCode }, `HTTP ${res.statusCode} redirect with no location header`);
}
else {
// console.log('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);
let redirectTo = url.resolve(u, res.headers.location);
download(redirectTo, httpOptions, redirects).then(resolve, reject);
}
else if (!res.headers.location) {
throw ono({ status: res.status }, `HTTP ${res.status} redirect with no location header`);
}
else {
resolve(res.body || Buffer.alloc(0));
// console.log('HTTP %d redirect %s -> %s', res.status, u.href, res.headers.location);
let redirectTo = url.resolve(u, res.headers.location);
return download(redirectTo, httpOptions, redirects);
}
})
.catch((err) => {
reject(new ResolverError(ono(err, `Error downloading ${u.href}`), u.href));
});
}));
}
else {
return res.body ? res.arrayBuffer().then(buf => Buffer.from(buf)) : Buffer.alloc(0);
}
})
.catch((err) => {
throw new ResolverError(ono(err, `Error downloading ${u.href}`), u.href);
});
}

@@ -144,40 +140,21 @@

function get (u, httpOptions) {
return new Promise(((resolve, reject) => {
// console.log('GET', u.href);
let controller;
let timeoutId;
if (httpOptions.timeout) {
controller = new AbortController();
timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout);
}
let protocol = u.protocol === "https:" ? https : http;
let req = protocol.get({
hostname: u.hostname,
port: u.port,
path: u.path,
auth: u.auth,
protocol: u.protocol,
headers: httpOptions.headers || {},
withCredentials: httpOptions.withCredentials
});
if (typeof req.setTimeout === "function") {
req.setTimeout(httpOptions.timeout);
return fetch(u, {
method: "GET",
headers: httpOptions.headers || {},
credentials: httpOptions.withCredentials ? "include" : "same-origin",
signal: controller ? controller.signal : null,
}).then(response => {
if (timeoutId) {
clearTimeout(timeoutId);
}
req.on("timeout", () => {
req.abort();
});
req.on("error", reject);
req.once("response", (res) => {
res.body = Buffer.alloc(0);
res.on("data", (data) => {
res.body = Buffer.concat([res.body, Buffer.from(data)]);
});
res.on("error", reject);
res.on("end", () => {
resolve(res);
});
});
}));
return response;
});
}
"use strict";
let isWindows = /^win/.test(process.platform),
const nodePath = require("path");
const projectDir = nodePath.resolve(__dirname, "..", "..");
let isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined),
forwardSlashPattern = /\//g,

@@ -25,6 +28,20 @@ protocolPattern = /^(\w{2,}):\/\//i,

exports.parse = require("url").parse;
exports.resolve = require("url").resolve;
exports.parse = (u) => new URL(u);
/**
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
*
* @return {string}
*/
exports.resolve = function resolve (from, to) {
let resolvedUrl = new URL(to, new URL(from, "resolve://"));
if (resolvedUrl.protocol === "resolve:") {
// `from` is a relative URL.
let { pathname, search, hash } = resolvedUrl;
return pathname + search + hash;
}
return resolvedUrl.toString();
};
/**
* Returns the current working directory (in Node) or the current page URL (in browsers).

@@ -35,3 +52,3 @@ *

exports.cwd = function cwd () {
if (process.browser) {
if (typeof window !== "undefined") {
return location.href;

@@ -135,3 +152,3 @@ }

// There is no protocol. If we're running in a browser, then assume it's HTTP.
return process.browser;
return typeof window !== "undefined";
}

@@ -182,3 +199,10 @@ else {

if (isWindows) {
path = path.replace(/\\/g, "/");
const hasProjectDir = path.toUpperCase().includes(projectDir.replace(/\\/g, "\\").toUpperCase());
const hasProjectUri = path.toUpperCase().includes(projectDir.replace(/\\/g, "/").toUpperCase());
if (hasProjectDir || hasProjectUri) {
path = path.replace(/\\/g, "/");
}
else {
path = `${projectDir}/${path}`.replace(/\\/g, "/");
}
}

@@ -185,0 +209,0 @@

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

@@ -25,2 +25,6 @@ "keywords": [

{
"name": "Phil Sturgeon",
"email": "phil@apisyouwonthate.com"
},
{
"name": "Jakub Rożek",

@@ -36,2 +40,3 @@ "email": "jakub@stoplight.io"

"license": "MIT",
"funding": "https://github.com/sponsors/philsturgeon",
"main": "lib/index.js",

@@ -42,2 +47,5 @@ "typings": "lib/index.d.ts",

},
"engines": {
"node": ">= 17"
},
"files": [

@@ -52,3 +60,3 @@ "lib"

"test:node": "mocha",
"test:browser": "karma start --single-run",
"test:browser": "cross-env NODE_OPTIONS=--openssl-legacy-provider karma start --single-run",
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts",

@@ -61,4 +69,4 @@ "coverage": "npm run coverage:node && npm run coverage:browser",

"devDependencies": {
"@amanda-mitchell/semantic-release-npm-multiple": "^2.5.0",
"@babel/polyfill": "^7.12.1",
"@chiragrupani/karma-chromium-edge-launcher": "^2.2.2",
"@jsdevtools/eslint-config": "^1.0.7",

@@ -68,8 +76,12 @@ "@jsdevtools/host-environment": "^2.1.2",

"@types/node": "^14.14.21",
"chai": "^4.2.0",
"chai-subset": "^1.6.0",
"chai": "^4.2.0",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"eslint": "^7.18.0",
"isomorphic-fetch": "^3.0.0",
"karma": "^5.0.2",
"karma-cli": "^2.0.0",
"karma": "^5.0.2",
"mocha": "^8.2.1",
"node-abort-controller": "^3.0.1",
"npm-check": "^5.9.0",

@@ -89,4 +101,3 @@ "nyc": "^15.0.1",

"branches": [
"main",
"v9"
"main"
],

@@ -105,15 +116,3 @@ "plugins": [

],
[
"@amanda-mitchell/semantic-release-npm-multiple",
{
"registries": {
"scoped": {
"pkgRoot": "."
},
"unscoped": {
"pkgRoot": "dist"
}
}
}
],
"@semantic-release/npm",
"@semantic-release/github"

@@ -120,0 +119,0 @@ ]

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

JSON Schema $Ref Parser
============================
# 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)_
#### Parse, Resolve, and Dereference JSON Schema $ref pointers

@@ -114,4 +116,11 @@

If you are using Node.js < 18, you'll need a polyfill for `fetch`, like [node-fetch](https://github.com/node-fetch/node-fetch):
```javascript
import fetch from "node-fetch";
globalThis.fetch = fetch;
```
Browser support

@@ -118,0 +127,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