@apidevtools/json-schema-ref-parser
Advanced tools
Comparing version 9.1.1 to 9.1.2
@@ -138,3 +138,3 @@ "use strict"; | ||
// Recursively crawl the resolved value | ||
if (!existingEntry || external) { | ||
if (!existingEntry) { | ||
crawl(pointer.value, null, pointer.path, pathFromRoot, indirections + 1, inventory, $refs, options); | ||
@@ -141,0 +141,0 @@ } |
@@ -74,5 +74,2 @@ "use strict"; | ||
obj[key] = dereferenced.value; | ||
if (options.dereference.onDereference) { | ||
options.dereference.onDereference(value.$ref, obj[key]); | ||
} | ||
} | ||
@@ -79,0 +76,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { JSONSchema4, JSONSchema4Object, JSONSchema4Type, JSONSchema6, JSONSchema6Object, JSONSchema6Type, JSONSchema7, JSONSchema7Object, JSONSchema7Type } from "json-schema"; | ||
import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema"; | ||
@@ -177,3 +177,2 @@ export = $RefParser; | ||
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7; | ||
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object; | ||
export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any; | ||
@@ -243,10 +242,2 @@ 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; | ||
}; | ||
@@ -253,0 +244,0 @@ } |
@@ -7,5 +7,2 @@ "use strict"; | ||
const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined); | ||
const getPathFromOs = filePath => isWindows ? filePath.replace(/\\/g, "/") : filePath; | ||
module.exports = $Refs; | ||
@@ -51,3 +48,3 @@ | ||
return paths.map((path) => { | ||
return getPathFromOs(path.decoded); | ||
return path.decoded; | ||
}); | ||
@@ -66,3 +63,3 @@ }; | ||
return paths.reduce((obj, path) => { | ||
obj[getPathFromOs(path.decoded)] = $refs[path.encoded].value; | ||
obj[path.decoded] = $refs[path.encoded].value; | ||
return obj; | ||
@@ -69,0 +66,0 @@ }, {}); |
"use strict"; | ||
const http = require("http"); | ||
const https = require("https"); | ||
const { ono } = require("@jsdevtools/ono"); | ||
@@ -76,3 +78,3 @@ const url = require("../util/url"); | ||
if (typeof window !== "undefined" && !u.protocol) { | ||
if (process.browser && !u.protocol) { | ||
// Use the protocol of the current page | ||
@@ -97,32 +99,34 @@ u.protocol = url.parse(location.href).protocol; | ||
function download (u, httpOptions, redirects) { | ||
u = url.parse(u); | ||
redirects = redirects || []; | ||
redirects.push(u.href); | ||
return new Promise(((resolve, reject) => { | ||
u = url.parse(u); | ||
redirects = redirects || []; | ||
redirects.push(u.href); | ||
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 ")}`)); | ||
get(u, httpOptions) | ||
.then((res) => { | ||
if (res.statusCode >= 400) { | ||
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.statusCode}`); | ||
} | ||
else if (!res.headers.location) { | ||
throw ono({ status: res.status }, `HTTP ${res.status} redirect with no location header`); | ||
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 { | ||
// 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); | ||
resolve(res.body || Buffer.alloc(0)); | ||
} | ||
} | ||
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); | ||
}); | ||
}) | ||
.catch((err) => { | ||
reject(new ResolverError(ono(err, `Error downloading ${u.href}`), u.href)); | ||
}); | ||
})); | ||
} | ||
@@ -140,21 +144,40 @@ | ||
function get (u, httpOptions) { | ||
let controller; | ||
let timeoutId; | ||
if (httpOptions.timeout) { | ||
controller = new AbortController(); | ||
timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout); | ||
} | ||
return new Promise(((resolve, reject) => { | ||
// console.log('GET', u.href); | ||
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); | ||
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 response; | ||
}); | ||
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); | ||
}); | ||
}); | ||
})); | ||
} |
"use strict"; | ||
const nodePath = require("path"); | ||
const projectDir = nodePath.resolve(__dirname, "..", ".."); | ||
let isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined), | ||
let isWindows = /^win/.test(process.platform), | ||
forwardSlashPattern = /\//g, | ||
@@ -28,20 +25,6 @@ protocolPattern = /^(\w{2,}):\/\//i, | ||
exports.parse = (u) => new URL(u); | ||
exports.parse = require("url").parse; | ||
exports.resolve = require("url").resolve; | ||
/** | ||
* 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). | ||
@@ -52,3 +35,3 @@ * | ||
exports.cwd = function cwd () { | ||
if (typeof window !== "undefined") { | ||
if (process.browser) { | ||
return location.href; | ||
@@ -152,3 +135,3 @@ } | ||
// There is no protocol. If we're running in a browser, then assume it's HTTP. | ||
return typeof window !== "undefined"; | ||
return process.browser; | ||
} | ||
@@ -199,10 +182,3 @@ else { | ||
if (isWindows) { | ||
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, "/"); | ||
} | ||
path = path.replace(/\\/g, "/"); | ||
} | ||
@@ -209,0 +185,0 @@ |
{ | ||
"name": "@apidevtools/json-schema-ref-parser", | ||
"version": "9.1.1", | ||
"version": "9.1.2", | ||
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", | ||
@@ -25,6 +25,2 @@ "keywords": [ | ||
{ | ||
"name": "Phil Sturgeon", | ||
"email": "phil@apisyouwonthate.com" | ||
}, | ||
{ | ||
"name": "Jakub Rożek", | ||
@@ -40,3 +36,2 @@ "email": "jakub@stoplight.io" | ||
"license": "MIT", | ||
"funding": "https://github.com/sponsors/philsturgeon", | ||
"main": "lib/index.js", | ||
@@ -47,5 +42,2 @@ "typings": "lib/index.d.ts", | ||
}, | ||
"engines": { | ||
"node": ">= 17" | ||
}, | ||
"files": [ | ||
@@ -60,3 +52,3 @@ "lib" | ||
"test:node": "mocha", | ||
"test:browser": "cross-env NODE_OPTIONS=--openssl-legacy-provider karma start --single-run", | ||
"test:browser": "karma start --single-run", | ||
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts", | ||
@@ -70,3 +62,2 @@ "coverage": "npm run coverage:node && npm run coverage:browser", | ||
"@babel/polyfill": "^7.12.1", | ||
"@chiragrupani/karma-chromium-edge-launcher": "^2.2.2", | ||
"@jsdevtools/eslint-config": "^1.0.7", | ||
@@ -78,10 +69,6 @@ "@jsdevtools/host-environment": "^2.1.2", | ||
"chai-subset": "^1.6.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", | ||
"mocha": "^8.2.1", | ||
"node-abort-controller": "^3.0.1", | ||
"npm-check": "^5.9.0", | ||
@@ -101,3 +88,8 @@ "nyc": "^15.0.1", | ||
"branches": [ | ||
"main" | ||
"main", | ||
"v9", | ||
{ | ||
"name": "v9.1.x", | ||
"range": "9.1.x" | ||
} | ||
], | ||
@@ -104,0 +96,0 @@ "plugins": [ |
@@ -1,5 +0,3 @@ | ||
# 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)_ | ||
JSON Schema $Ref Parser | ||
============================ | ||
#### Parse, Resolve, and Dereference JSON Schema $ref pointers | ||
@@ -116,11 +114,4 @@ | ||
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 | ||
@@ -127,0 +118,0 @@ -------------------------- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16
0
139513
3156
163
2