@apidevtools/json-schema-ref-parser 9.0.5 → 9.0.6
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 +1 -1
- package/lib/dereference.js +8 -2
- package/lib/pointer.js +11 -3
- package/lib/ref.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -129,7 +129,7 @@ Full API documentation is available [right here](https://apitools.dev/json-schem
|
|
|
129
129
|
|
|
130
130
|
Contributing
|
|
131
131
|
--------------------------
|
|
132
|
-
I welcome any contributions, enhancements, and bug-fixes. [
|
|
132
|
+
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/json-schema-ref-parser/pulls).
|
|
133
133
|
|
|
134
134
|
#### Building/Testing
|
|
135
135
|
To build/test the project locally on your computer:
|
package/lib/dereference.js
CHANGED
|
@@ -57,13 +57,19 @@ function crawl (obj, path, pathFromRoot, parents, $refs, options) {
|
|
|
57
57
|
if ($Ref.isAllowed$Ref(value, options)) {
|
|
58
58
|
dereferenced = dereference$Ref(value, keyPath, keyPathFromRoot, parents, $refs, options);
|
|
59
59
|
circular = dereferenced.circular;
|
|
60
|
-
|
|
60
|
+
// Avoid pointless mutations; breaks frozen objects to no profit
|
|
61
|
+
if (obj[key] !== dereferenced.value) {
|
|
62
|
+
obj[key] = dereferenced.value;
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
else {
|
|
63
66
|
if (parents.indexOf(value) === -1) {
|
|
64
67
|
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, $refs, options);
|
|
65
68
|
circular = dereferenced.circular;
|
|
66
|
-
|
|
69
|
+
// Avoid pointless mutations; breaks frozen objects to no profit
|
|
70
|
+
if (obj[key] !== dereferenced.value) {
|
|
71
|
+
obj[key] = dereferenced.value;
|
|
72
|
+
}
|
|
67
73
|
}
|
|
68
74
|
else {
|
|
69
75
|
circular = foundCircularReference(keyPath, $refs, options);
|
package/lib/pointer.js
CHANGED
|
@@ -64,6 +64,7 @@ function Pointer ($ref, path, friendlyPath) {
|
|
|
64
64
|
*
|
|
65
65
|
* @param {*} obj - The object that will be crawled
|
|
66
66
|
* @param {$RefParserOptions} options
|
|
67
|
+
* @param {string} pathFromRoot - the path of place that initiated resolving
|
|
67
68
|
*
|
|
68
69
|
* @returns {Pointer}
|
|
69
70
|
* Returns a JSON pointer whose {@link Pointer#value} is the resolved value.
|
|
@@ -71,7 +72,7 @@ function Pointer ($ref, path, friendlyPath) {
|
|
|
71
72
|
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
|
|
72
73
|
* of the resolved value.
|
|
73
74
|
*/
|
|
74
|
-
Pointer.prototype.resolve = function (obj, options) {
|
|
75
|
+
Pointer.prototype.resolve = function (obj, options, pathFromRoot) {
|
|
75
76
|
let tokens = Pointer.parse(this.path, this.originalPath);
|
|
76
77
|
|
|
77
78
|
// Crawl the object, one token at a time
|
|
@@ -83,6 +84,10 @@ Pointer.prototype.resolve = function (obj, options) {
|
|
|
83
84
|
this.path = Pointer.join(this.path, tokens.slice(i));
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
let token = tokens[i];
|
|
87
92
|
if (this.value[token] === undefined || this.value[token] === null) {
|
|
88
93
|
this.value = null;
|
|
@@ -94,7 +99,10 @@ Pointer.prototype.resolve = function (obj, options) {
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
// Resolve the final value
|
|
97
|
-
|
|
102
|
+
if (!this.value || this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot) {
|
|
103
|
+
resolveIf$Ref(this, options);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
return this;
|
|
99
107
|
};
|
|
100
108
|
|
|
@@ -226,7 +234,7 @@ function resolveIf$Ref (pointer, options) {
|
|
|
226
234
|
pointer.circular = true;
|
|
227
235
|
}
|
|
228
236
|
else {
|
|
229
|
-
let resolved = pointer.$ref.$refs._resolve($refPath,
|
|
237
|
+
let resolved = pointer.$ref.$refs._resolve($refPath, pointer.path, options);
|
|
230
238
|
pointer.indirections += resolved.indirections + 1;
|
|
231
239
|
|
|
232
240
|
if ($Ref.isExtended$Ref(pointer.value)) {
|
package/lib/ref.js
CHANGED
|
@@ -112,7 +112,7 @@ $Ref.prototype.get = function (path, options) {
|
|
|
112
112
|
$Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
|
|
113
113
|
let pointer = new Pointer(this, path, friendlyPath);
|
|
114
114
|
try {
|
|
115
|
-
return pointer.resolve(this.value, options);
|
|
115
|
+
return pointer.resolve(this.value, options, pathFromRoot);
|
|
116
116
|
}
|
|
117
117
|
catch (err) {
|
|
118
118
|
if (!options || !options.continueOnError || !isHandledError(err)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apidevtools/json-schema-ref-parser",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.6",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/polyfill": "^7.10.4",
|
|
55
|
-
"@jsdevtools/eslint-config": "^1.0.
|
|
55
|
+
"@jsdevtools/eslint-config": "^1.0.7",
|
|
56
56
|
"@jsdevtools/host-environment": "^2.0.4",
|
|
57
57
|
"@jsdevtools/karma-config": "^3.1.7",
|
|
58
58
|
"@jsdevtools/version-bump-prompt": "^6.0.6",
|
|
59
59
|
"@types/json-schema": "^7.0.4",
|
|
60
|
-
"@types/node": "^14.0.
|
|
60
|
+
"@types/node": "^14.0.25",
|
|
61
61
|
"chai": "^4.2.0",
|
|
62
62
|
"chai-subset": "^1.6.0",
|
|
63
63
|
"eslint": "^7.5.0",
|