@apidevtools/json-schema-ref-parser 14.0.2 → 14.0.3
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/dist/lib/index.js +14 -16
- package/dist/lib/pointer.js +27 -0
- package/dist/lib/ref.js +32 -4
- package/dist/lib/refs.js +39 -26
- package/dist/lib/resolve-external.js +1 -1
- package/dist/lib/resolvers/http.js +1 -1
- package/dist/lib/util/errors.js +27 -16
- package/dist/lib/util/plugins.js +1 -1
- package/lib/util/plugins.ts +1 -1
- package/package.json +12 -13
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -19
package/dist/lib/index.js
CHANGED
|
@@ -69,22 +69,20 @@ Object.defineProperty(exports, "isUnsafeUrl", { enumerable: true, get: function
|
|
|
69
69
|
* @class
|
|
70
70
|
*/
|
|
71
71
|
class $RefParser {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.$refs = new refs_js_1.default();
|
|
87
|
-
}
|
|
72
|
+
/**
|
|
73
|
+
* The parsed (and possibly dereferenced) JSON schema object
|
|
74
|
+
*
|
|
75
|
+
* @type {object}
|
|
76
|
+
* @readonly
|
|
77
|
+
*/
|
|
78
|
+
schema = null;
|
|
79
|
+
/**
|
|
80
|
+
* The resolved JSON references
|
|
81
|
+
*
|
|
82
|
+
* @type {$Refs}
|
|
83
|
+
* @readonly
|
|
84
|
+
*/
|
|
85
|
+
$refs = new refs_js_1.default();
|
|
88
86
|
async parse() {
|
|
89
87
|
const args = (0, normalize_args_js_1.default)(arguments);
|
|
90
88
|
let promise;
|
package/dist/lib/pointer.js
CHANGED
|
@@ -62,6 +62,33 @@ const safeDecodeURIComponent = (encodedURIComponent) => {
|
|
|
62
62
|
* @class
|
|
63
63
|
*/
|
|
64
64
|
class Pointer {
|
|
65
|
+
/**
|
|
66
|
+
* The {@link $Ref} object that contains this {@link Pointer} object.
|
|
67
|
+
*/
|
|
68
|
+
$ref;
|
|
69
|
+
/**
|
|
70
|
+
* The file path or URL, containing the JSON pointer in the hash.
|
|
71
|
+
* This path is relative to the path of the main JSON schema file.
|
|
72
|
+
*/
|
|
73
|
+
path;
|
|
74
|
+
/**
|
|
75
|
+
* The original path or URL, used for error messages.
|
|
76
|
+
*/
|
|
77
|
+
originalPath;
|
|
78
|
+
/**
|
|
79
|
+
* The value of the JSON pointer.
|
|
80
|
+
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
81
|
+
*/
|
|
82
|
+
value;
|
|
83
|
+
/**
|
|
84
|
+
* Indicates whether the pointer references itself.
|
|
85
|
+
*/
|
|
86
|
+
circular;
|
|
87
|
+
/**
|
|
88
|
+
* The number of indirect references that were traversed to resolve the value.
|
|
89
|
+
* Resolving a single pointer may require resolving multiple $Refs.
|
|
90
|
+
*/
|
|
91
|
+
indirections;
|
|
65
92
|
constructor($ref, path, friendlyPath) {
|
|
66
93
|
this.$ref = $ref;
|
|
67
94
|
this.path = path;
|
package/dist/lib/ref.js
CHANGED
|
@@ -42,11 +42,39 @@ const url_js_1 = require("./util/url.js");
|
|
|
42
42
|
* @class
|
|
43
43
|
*/
|
|
44
44
|
class $Ref {
|
|
45
|
+
/**
|
|
46
|
+
* The file path or URL of the referenced file.
|
|
47
|
+
* This path is relative to the path of the main JSON schema file.
|
|
48
|
+
*
|
|
49
|
+
* This path does NOT contain document fragments (JSON pointers). It always references an ENTIRE file.
|
|
50
|
+
* Use methods such as {@link $Ref#get}, {@link $Ref#resolve}, and {@link $Ref#exists} to get
|
|
51
|
+
* specific JSON pointers within the file.
|
|
52
|
+
*
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
55
|
+
path;
|
|
56
|
+
/**
|
|
57
|
+
* The resolved value of the JSON reference.
|
|
58
|
+
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
59
|
+
*
|
|
60
|
+
* @type {?*}
|
|
61
|
+
*/
|
|
62
|
+
value;
|
|
63
|
+
/**
|
|
64
|
+
* The {@link $Refs} object that contains this {@link $Ref} object.
|
|
65
|
+
*
|
|
66
|
+
* @type {$Refs}
|
|
67
|
+
*/
|
|
68
|
+
$refs;
|
|
69
|
+
/**
|
|
70
|
+
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
|
|
71
|
+
*/
|
|
72
|
+
pathType;
|
|
73
|
+
/**
|
|
74
|
+
* List of all errors. Undefined if no errors.
|
|
75
|
+
*/
|
|
76
|
+
errors = [];
|
|
45
77
|
constructor($refs) {
|
|
46
|
-
/**
|
|
47
|
-
* List of all errors. Undefined if no errors.
|
|
48
|
-
*/
|
|
49
|
-
this.errors = [];
|
|
50
78
|
this.$refs = $refs;
|
|
51
79
|
}
|
|
52
80
|
/**
|
package/dist/lib/refs.js
CHANGED
|
@@ -47,6 +47,12 @@ const convert_path_to_posix_1 = __importDefault(require("./util/convert-path-to-
|
|
|
47
47
|
* See https://apidevtools.com/json-schema-ref-parser/docs/refs.html
|
|
48
48
|
*/
|
|
49
49
|
class $Refs {
|
|
50
|
+
/**
|
|
51
|
+
* This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.
|
|
52
|
+
*
|
|
53
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/refs.html#circular
|
|
54
|
+
*/
|
|
55
|
+
circular;
|
|
50
56
|
/**
|
|
51
57
|
* Returns the paths/URLs of all the files in your schema (including the main schema file).
|
|
52
58
|
*
|
|
@@ -166,33 +172,21 @@ class $Refs {
|
|
|
166
172
|
}
|
|
167
173
|
return $ref.resolve(absPath, options, path, pathFromRoot);
|
|
168
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* A map of paths/urls to {@link $Ref} objects
|
|
177
|
+
*
|
|
178
|
+
* @type {object}
|
|
179
|
+
* @protected
|
|
180
|
+
*/
|
|
181
|
+
_$refs = {};
|
|
182
|
+
/**
|
|
183
|
+
* The {@link $Ref} object that is the root of the JSON schema.
|
|
184
|
+
*
|
|
185
|
+
* @type {$Ref}
|
|
186
|
+
* @protected
|
|
187
|
+
*/
|
|
188
|
+
_root$Ref;
|
|
169
189
|
constructor() {
|
|
170
|
-
/**
|
|
171
|
-
* A map of paths/urls to {@link $Ref} objects
|
|
172
|
-
*
|
|
173
|
-
* @type {object}
|
|
174
|
-
* @protected
|
|
175
|
-
*/
|
|
176
|
-
this._$refs = {};
|
|
177
|
-
/**
|
|
178
|
-
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
|
179
|
-
* including the schema itself.
|
|
180
|
-
*
|
|
181
|
-
* @param [types] - Only return paths of the given types ("file", "http", etc.)
|
|
182
|
-
* @returns
|
|
183
|
-
*/
|
|
184
|
-
/**
|
|
185
|
-
* Returns the map of JSON references and their resolved values.
|
|
186
|
-
*
|
|
187
|
-
* @param [types] - Only return references of the given types ("file", "http", etc.)
|
|
188
|
-
* @returns
|
|
189
|
-
*/
|
|
190
|
-
/**
|
|
191
|
-
* Returns a POJO (plain old JavaScript object) for serialization as JSON.
|
|
192
|
-
*
|
|
193
|
-
* @returns {object}
|
|
194
|
-
*/
|
|
195
|
-
this.toJSON = this.values;
|
|
196
190
|
/**
|
|
197
191
|
* Indicates whether the schema contains any circular references.
|
|
198
192
|
*
|
|
@@ -203,6 +197,25 @@ class $Refs {
|
|
|
203
197
|
// @ts-ignore
|
|
204
198
|
this._root$Ref = null;
|
|
205
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
|
202
|
+
* including the schema itself.
|
|
203
|
+
*
|
|
204
|
+
* @param [types] - Only return paths of the given types ("file", "http", etc.)
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* Returns the map of JSON references and their resolved values.
|
|
209
|
+
*
|
|
210
|
+
* @param [types] - Only return references of the given types ("file", "http", etc.)
|
|
211
|
+
* @returns
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* Returns a POJO (plain old JavaScript object) for serialization as JSON.
|
|
215
|
+
*
|
|
216
|
+
* @returns {object}
|
|
217
|
+
*/
|
|
218
|
+
toJSON = this.values;
|
|
206
219
|
}
|
|
207
220
|
exports.default = $Refs;
|
|
208
221
|
/**
|
|
@@ -82,7 +82,7 @@ function resolveExternal(parser, options) {
|
|
|
82
82
|
* then the corresponding promise will internally reference an array of promises.
|
|
83
83
|
*/
|
|
84
84
|
function crawl(obj, path, $refs, options, seen, external) {
|
|
85
|
-
seen
|
|
85
|
+
seen ||= new Set();
|
|
86
86
|
let promises = [];
|
|
87
87
|
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) {
|
|
88
88
|
seen.add(obj); // Track previously seen objects to avoid infinite recursion
|
|
@@ -53,7 +53,7 @@ exports.default = {
|
|
|
53
53
|
/**
|
|
54
54
|
* HTTP request timeout (in milliseconds).
|
|
55
55
|
*/
|
|
56
|
-
timeout:
|
|
56
|
+
timeout: 60_000, // 60 seconds
|
|
57
57
|
/**
|
|
58
58
|
* The maximum number of HTTP redirects to follow.
|
|
59
59
|
* To disable automatic following of redirects, set this to zero.
|
package/dist/lib/util/errors.js
CHANGED
|
@@ -49,28 +49,34 @@ function getDeepKeys(obj, omit = []) {
|
|
|
49
49
|
return uniqueKeys;
|
|
50
50
|
}
|
|
51
51
|
class JSONParserError extends Error {
|
|
52
|
+
name;
|
|
53
|
+
message;
|
|
54
|
+
source;
|
|
55
|
+
path;
|
|
56
|
+
code;
|
|
52
57
|
constructor(message, source) {
|
|
53
58
|
super();
|
|
54
|
-
this.toJSON = toJSON.bind(this);
|
|
55
59
|
this.code = "EUNKNOWN";
|
|
56
60
|
this.name = "JSONParserError";
|
|
57
61
|
this.message = message;
|
|
58
62
|
this.source = source;
|
|
59
63
|
this.path = null;
|
|
60
64
|
}
|
|
65
|
+
toJSON = toJSON.bind(this);
|
|
61
66
|
get footprint() {
|
|
62
67
|
return `${this.path}+${this.source}+${this.code}+${this.message}`;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
exports.JSONParserError = JSONParserError;
|
|
66
71
|
class JSONParserErrorGroup extends Error {
|
|
72
|
+
files;
|
|
67
73
|
constructor(parser) {
|
|
68
74
|
super();
|
|
69
|
-
this.toJSON = toJSON.bind(this);
|
|
70
75
|
this.files = parser;
|
|
71
76
|
this.name = "JSONParserErrorGroup";
|
|
72
77
|
this.message = `${this.errors.length} error${this.errors.length > 1 ? "s" : ""} occurred while reading '${(0, url_js_1.toFileSystemPath)(parser.$refs._root$Ref.path)}'`;
|
|
73
78
|
}
|
|
79
|
+
toJSON = toJSON.bind(this);
|
|
74
80
|
static getParserErrors(parser) {
|
|
75
81
|
const errors = [];
|
|
76
82
|
for (const $ref of Object.values(parser.$refs._$refs)) {
|
|
@@ -86,26 +92,27 @@ class JSONParserErrorGroup extends Error {
|
|
|
86
92
|
}
|
|
87
93
|
exports.JSONParserErrorGroup = JSONParserErrorGroup;
|
|
88
94
|
class ParserError extends JSONParserError {
|
|
95
|
+
code = "EPARSER";
|
|
96
|
+
name = "ParserError";
|
|
89
97
|
constructor(message, source) {
|
|
90
98
|
super(`Error parsing ${source}: ${message}`, source);
|
|
91
|
-
this.code = "EPARSER";
|
|
92
|
-
this.name = "ParserError";
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
exports.ParserError = ParserError;
|
|
96
102
|
class UnmatchedParserError extends JSONParserError {
|
|
103
|
+
code = "EUNMATCHEDPARSER";
|
|
104
|
+
name = "UnmatchedParserError";
|
|
97
105
|
constructor(source) {
|
|
98
106
|
super(`Could not find parser for "${source}"`, source);
|
|
99
|
-
this.code = "EUNMATCHEDPARSER";
|
|
100
|
-
this.name = "UnmatchedParserError";
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
exports.UnmatchedParserError = UnmatchedParserError;
|
|
104
110
|
class ResolverError extends JSONParserError {
|
|
111
|
+
code = "ERESOLVER";
|
|
112
|
+
name = "ResolverError";
|
|
113
|
+
ioErrorCode;
|
|
105
114
|
constructor(ex, source) {
|
|
106
115
|
super(ex.message || `Error reading file "${source}"`, source);
|
|
107
|
-
this.code = "ERESOLVER";
|
|
108
|
-
this.name = "ResolverError";
|
|
109
116
|
if ("code" in ex) {
|
|
110
117
|
this.ioErrorCode = String(ex.code);
|
|
111
118
|
}
|
|
@@ -113,18 +120,22 @@ class ResolverError extends JSONParserError {
|
|
|
113
120
|
}
|
|
114
121
|
exports.ResolverError = ResolverError;
|
|
115
122
|
class UnmatchedResolverError extends JSONParserError {
|
|
123
|
+
code = "EUNMATCHEDRESOLVER";
|
|
124
|
+
name = "UnmatchedResolverError";
|
|
116
125
|
constructor(source) {
|
|
117
126
|
super(`Could not find resolver for "${source}"`, source);
|
|
118
|
-
this.code = "EUNMATCHEDRESOLVER";
|
|
119
|
-
this.name = "UnmatchedResolverError";
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
exports.UnmatchedResolverError = UnmatchedResolverError;
|
|
123
130
|
class MissingPointerError extends JSONParserError {
|
|
131
|
+
code = "EMISSINGPOINTER";
|
|
132
|
+
name = "MissingPointerError";
|
|
133
|
+
targetToken;
|
|
134
|
+
targetRef;
|
|
135
|
+
targetFound;
|
|
136
|
+
parentPath;
|
|
124
137
|
constructor(token, path, targetRef, targetFound, parentPath) {
|
|
125
138
|
super(`Missing $ref pointer "${(0, url_js_1.getHash)(path)}". Token "${token}" does not exist.`, (0, url_js_1.stripHash)(path));
|
|
126
|
-
this.code = "EMISSINGPOINTER";
|
|
127
|
-
this.name = "MissingPointerError";
|
|
128
139
|
this.targetToken = token;
|
|
129
140
|
this.targetRef = targetRef;
|
|
130
141
|
this.targetFound = targetFound;
|
|
@@ -133,18 +144,18 @@ class MissingPointerError extends JSONParserError {
|
|
|
133
144
|
}
|
|
134
145
|
exports.MissingPointerError = MissingPointerError;
|
|
135
146
|
class TimeoutError extends JSONParserError {
|
|
147
|
+
code = "ETIMEOUT";
|
|
148
|
+
name = "TimeoutError";
|
|
136
149
|
constructor(timeout) {
|
|
137
150
|
super(`Dereferencing timeout reached: ${timeout}ms`);
|
|
138
|
-
this.code = "ETIMEOUT";
|
|
139
|
-
this.name = "TimeoutError";
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
exports.TimeoutError = TimeoutError;
|
|
143
154
|
class InvalidPointerError extends JSONParserError {
|
|
155
|
+
code = "EUNMATCHEDRESOLVER";
|
|
156
|
+
name = "InvalidPointerError";
|
|
144
157
|
constructor(pointer, path) {
|
|
145
158
|
super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, (0, url_js_1.stripHash)(path));
|
|
146
|
-
this.code = "EUNMATCHEDRESOLVER";
|
|
147
|
-
this.name = "InvalidPointerError";
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
exports.InvalidPointerError = InvalidPointerError;
|
package/dist/lib/util/plugins.js
CHANGED
package/lib/util/plugins.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apidevtools/json-schema-ref-parser",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.3",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepublishOnly": "yarn build",
|
|
@@ -59,36 +59,35 @@
|
|
|
59
59
|
"fs": false
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
62
|
+
"node": ">= 20"
|
|
63
63
|
},
|
|
64
64
|
"files": [
|
|
65
65
|
"lib",
|
|
66
|
-
"dist"
|
|
67
|
-
"cjs"
|
|
66
|
+
"dist"
|
|
68
67
|
],
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@eslint/compat": "^1.3.
|
|
71
|
-
"@eslint/js": "^9.
|
|
69
|
+
"@eslint/compat": "^1.3.1",
|
|
70
|
+
"@eslint/js": "^9.30.0",
|
|
72
71
|
"@types/eslint": "^9.6.1",
|
|
73
72
|
"@types/js-yaml": "^4.0.9",
|
|
74
73
|
"@types/node": "^24",
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
76
|
-
"@typescript-eslint/parser": "^8.
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
|
75
|
+
"@typescript-eslint/parser": "^8.35.1",
|
|
77
76
|
"@vitest/coverage-v8": "^3.2.4",
|
|
78
77
|
"cross-env": "^7.0.3",
|
|
79
|
-
"eslint": "^9.
|
|
78
|
+
"eslint": "^9.30.0",
|
|
80
79
|
"eslint-config-prettier": "^10.1.5",
|
|
81
80
|
"eslint-config-standard": "^17.1.0",
|
|
82
|
-
"eslint-plugin-import": "^2.
|
|
83
|
-
"eslint-plugin-prettier": "^5.5.
|
|
81
|
+
"eslint-plugin-import": "^2.32.0",
|
|
82
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
84
83
|
"eslint-plugin-promise": "^7.2.1",
|
|
85
84
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
86
85
|
"globals": "^16.2.0",
|
|
87
86
|
"jsdom": "^26.1.0",
|
|
88
|
-
"prettier": "^3.
|
|
87
|
+
"prettier": "^3.6.2",
|
|
89
88
|
"rimraf": "^6.0.1",
|
|
90
89
|
"typescript": "^5.8.3",
|
|
91
|
-
"typescript-eslint": "^8.
|
|
90
|
+
"typescript-eslint": "^8.35.1",
|
|
92
91
|
"vitest": "^3.2.4"
|
|
93
92
|
},
|
|
94
93
|
"dependencies": {
|
package/dist/vite.config.d.ts
DELETED
package/dist/vite.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_1 = require("vitest/config");
|
|
4
|
-
const isBrowser = process.env.BROWSER === "true";
|
|
5
|
-
exports.default = (0, config_1.defineConfig)({
|
|
6
|
-
test: {
|
|
7
|
-
environment: isBrowser ? "jsdom" : "node",
|
|
8
|
-
dir: "test",
|
|
9
|
-
exclude: ["**/__IGNORED__/**"],
|
|
10
|
-
watch: false,
|
|
11
|
-
globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined,
|
|
12
|
-
testTimeout: 5000,
|
|
13
|
-
globals: true,
|
|
14
|
-
passWithNoTests: true,
|
|
15
|
-
reporters: ["verbose"],
|
|
16
|
-
coverage: { reporter: ["lcov", "html", "text"] },
|
|
17
|
-
snapshotSerializers: ["./test/utils/serializeJson.ts"],
|
|
18
|
-
},
|
|
19
|
-
});
|