@apidevtools/json-schema-ref-parser 11.1.0 → 11.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# JSON Schema $Ref Parser
|
|
2
2
|
|
|
3
|
-
_**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)_
|
|
4
|
-
|
|
5
3
|
#### Parse, Resolve, and Dereference JSON Schema $ref pointers
|
|
6
4
|
|
|
7
5
|
[](https://github.com/APIDevTools/json-schema-ref-parser/actions)
|
package/dist/lib/pointer.js
CHANGED
|
@@ -68,11 +68,11 @@ class Pointer {
|
|
|
68
68
|
// Crawl the object, one token at a time
|
|
69
69
|
this.value = unwrapOrThrow(obj);
|
|
70
70
|
for (let i = 0; i < tokens.length; i++) {
|
|
71
|
-
if (resolveIf$Ref(this, options)) {
|
|
71
|
+
if (resolveIf$Ref(this, options, pathFromRoot)) {
|
|
72
72
|
// The $ref path has changed, so append the remaining tokens to the path
|
|
73
73
|
this.path = Pointer.join(this.path, tokens.slice(i));
|
|
74
74
|
}
|
|
75
|
-
if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
|
|
75
|
+
if (typeof this.value === "object" && this.value !== null && !isRootPath(pathFromRoot) && "$ref" in this.value) {
|
|
76
76
|
return this;
|
|
77
77
|
}
|
|
78
78
|
const token = tokens[i];
|
|
@@ -86,7 +86,7 @@ class Pointer {
|
|
|
86
86
|
}
|
|
87
87
|
// Resolve the final value
|
|
88
88
|
if (!this.value || (this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot)) {
|
|
89
|
-
resolveIf$Ref(this, options);
|
|
89
|
+
resolveIf$Ref(this, options, pathFromRoot);
|
|
90
90
|
}
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
@@ -190,13 +190,14 @@ class Pointer {
|
|
|
190
190
|
*
|
|
191
191
|
* @param pointer
|
|
192
192
|
* @param options
|
|
193
|
+
* @param [pathFromRoot] - the path of place that initiated resolving
|
|
193
194
|
* @returns - Returns `true` if the resolution path changed
|
|
194
195
|
*/
|
|
195
|
-
function resolveIf$Ref(pointer, options) {
|
|
196
|
+
function resolveIf$Ref(pointer, options, pathFromRoot) {
|
|
196
197
|
// Is the value a JSON reference? (and allowed?)
|
|
197
198
|
if (ref_js_1.default.isAllowed$Ref(pointer.value, options)) {
|
|
198
199
|
const $refPath = url.resolve(pointer.path, pointer.value.$ref);
|
|
199
|
-
if ($refPath === pointer.path) {
|
|
200
|
+
if ($refPath === pointer.path && !isRootPath(pathFromRoot)) {
|
|
200
201
|
// The value is a reference to itself, so there's nothing to do.
|
|
201
202
|
pointer.circular = true;
|
|
202
203
|
}
|
|
@@ -254,3 +255,6 @@ function unwrapOrThrow(value) {
|
|
|
254
255
|
}
|
|
255
256
|
return value;
|
|
256
257
|
}
|
|
258
|
+
function isRootPath(pathFromRoot) {
|
|
259
|
+
return typeof pathFromRoot == "string" && Pointer.parse(pathFromRoot).length == 0;
|
|
260
|
+
}
|
|
@@ -9,6 +9,6 @@ function convertPathToPosix(filePath) {
|
|
|
9
9
|
if (isExtendedLengthPath) {
|
|
10
10
|
return filePath;
|
|
11
11
|
}
|
|
12
|
-
return filePath.split(path_1.default
|
|
12
|
+
return filePath.split(path_1.default?.win32?.sep).join(path_1.default.posix.sep);
|
|
13
13
|
}
|
|
14
14
|
exports.default = convertPathToPosix;
|
package/lib/pointer.ts
CHANGED
|
@@ -83,12 +83,12 @@ class Pointer {
|
|
|
83
83
|
this.value = unwrapOrThrow(obj);
|
|
84
84
|
|
|
85
85
|
for (let i = 0; i < tokens.length; i++) {
|
|
86
|
-
if (resolveIf$Ref(this, options)) {
|
|
86
|
+
if (resolveIf$Ref(this, options, pathFromRoot)) {
|
|
87
87
|
// The $ref path has changed, so append the remaining tokens to the path
|
|
88
88
|
this.path = Pointer.join(this.path, tokens.slice(i));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
|
|
91
|
+
if (typeof this.value === "object" && this.value !== null && !isRootPath(pathFromRoot) && "$ref" in this.value) {
|
|
92
92
|
return this;
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -103,7 +103,7 @@ class Pointer {
|
|
|
103
103
|
|
|
104
104
|
// Resolve the final value
|
|
105
105
|
if (!this.value || (this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot)) {
|
|
106
|
-
resolveIf$Ref(this, options);
|
|
106
|
+
resolveIf$Ref(this, options, pathFromRoot);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
return this;
|
|
@@ -224,15 +224,16 @@ class Pointer {
|
|
|
224
224
|
*
|
|
225
225
|
* @param pointer
|
|
226
226
|
* @param options
|
|
227
|
+
* @param [pathFromRoot] - the path of place that initiated resolving
|
|
227
228
|
* @returns - Returns `true` if the resolution path changed
|
|
228
229
|
*/
|
|
229
|
-
function resolveIf$Ref(pointer: any, options: any) {
|
|
230
|
+
function resolveIf$Ref(pointer: any, options: any, pathFromRoot?: any) {
|
|
230
231
|
// Is the value a JSON reference? (and allowed?)
|
|
231
232
|
|
|
232
233
|
if ($Ref.isAllowed$Ref(pointer.value, options)) {
|
|
233
234
|
const $refPath = url.resolve(pointer.path, pointer.value.$ref);
|
|
234
235
|
|
|
235
|
-
if ($refPath === pointer.path) {
|
|
236
|
+
if ($refPath === pointer.path && !isRootPath(pathFromRoot)) {
|
|
236
237
|
// The value is a reference to itself, so there's nothing to do.
|
|
237
238
|
pointer.circular = true;
|
|
238
239
|
} else {
|
|
@@ -294,3 +295,7 @@ function unwrapOrThrow(value: any) {
|
|
|
294
295
|
|
|
295
296
|
return value;
|
|
296
297
|
}
|
|
298
|
+
|
|
299
|
+
function isRootPath(pathFromRoot: any): boolean {
|
|
300
|
+
return typeof pathFromRoot == "string" && Pointer.parse(pathFromRoot).length == 0;
|
|
301
|
+
}
|