@apidevtools/json-schema-ref-parser 11.7.2 → 11.8.2
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 +4 -8
- package/cjs/bundle.js +304 -0
- package/cjs/dereference.js +258 -0
- package/cjs/index.js +603 -0
- package/cjs/normalize-args.js +64 -0
- package/cjs/options.js +125 -0
- package/cjs/package.json +3 -0
- package/cjs/parse.js +338 -0
- package/cjs/parsers/binary.js +54 -0
- package/cjs/parsers/json.js +199 -0
- package/cjs/parsers/text.js +61 -0
- package/cjs/parsers/yaml.js +239 -0
- package/cjs/pointer.js +290 -0
- package/cjs/ref.js +333 -0
- package/cjs/refs.js +214 -0
- package/cjs/resolve-external.js +333 -0
- package/cjs/resolvers/file.js +106 -0
- package/cjs/resolvers/http.js +184 -0
- package/cjs/util/errors.js +401 -0
- package/cjs/util/plugins.js +159 -0
- package/cjs/util/projectDir.cjs +6 -0
- package/cjs/util/url.js +228 -0
- package/dist/lib/bundle.js +17 -7
- package/dist/lib/dereference.js +20 -8
- package/dist/lib/index.d.ts +6 -6
- package/dist/lib/index.js +17 -7
- package/dist/lib/options.d.ts +9 -2
- package/dist/lib/parse.d.ts +1 -1
- package/dist/lib/parse.js +17 -7
- package/dist/lib/pointer.js +25 -9
- package/dist/lib/refs.js +17 -7
- package/dist/lib/resolve-external.js +17 -7
- package/dist/lib/resolvers/file.js +17 -7
- package/dist/lib/resolvers/http.js +17 -7
- package/dist/lib/util/errors.d.ts +6 -2
- package/dist/lib/util/errors.js +7 -3
- package/dist/lib/util/plugins.d.ts +2 -2
- package/dist/lib/util/url.js +20 -9
- package/lib/dereference.ts +4 -1
- package/lib/index.ts +6 -12
- package/lib/options.ts +7 -0
- package/lib/pointer.ts +13 -2
- package/lib/util/errors.ts +14 -5
- package/lib/util/plugins.ts +6 -7
- package/lib/util/url.ts +3 -2
- package/package.json +31 -31
package/cjs/index.js
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
default: function() {
|
|
13
|
+
return _default;
|
|
14
|
+
},
|
|
15
|
+
JSONParserError: function() {
|
|
16
|
+
return _errorsJs.JSONParserError;
|
|
17
|
+
},
|
|
18
|
+
InvalidPointerError: function() {
|
|
19
|
+
return _errorsJs.InvalidPointerError;
|
|
20
|
+
},
|
|
21
|
+
MissingPointerError: function() {
|
|
22
|
+
return _errorsJs.MissingPointerError;
|
|
23
|
+
},
|
|
24
|
+
ResolverError: function() {
|
|
25
|
+
return _errorsJs.ResolverError;
|
|
26
|
+
},
|
|
27
|
+
ParserError: function() {
|
|
28
|
+
return _errorsJs.ParserError;
|
|
29
|
+
},
|
|
30
|
+
UnmatchedParserError: function() {
|
|
31
|
+
return _errorsJs.UnmatchedParserError;
|
|
32
|
+
},
|
|
33
|
+
UnmatchedResolverError: function() {
|
|
34
|
+
return _errorsJs.UnmatchedResolverError;
|
|
35
|
+
},
|
|
36
|
+
parse: function() {
|
|
37
|
+
return parse;
|
|
38
|
+
},
|
|
39
|
+
resolve: function() {
|
|
40
|
+
return resolve;
|
|
41
|
+
},
|
|
42
|
+
bundle: function() {
|
|
43
|
+
return bundle;
|
|
44
|
+
},
|
|
45
|
+
dereference: function() {
|
|
46
|
+
return dereference;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var _refsJs = /*#__PURE__*/ _interopRequireDefault(require("./refs.js"));
|
|
50
|
+
var _parseJs = /*#__PURE__*/ _interopRequireDefault(require("./parse.js"));
|
|
51
|
+
var _normalizeArgsJs = /*#__PURE__*/ _interopRequireDefault(require("./normalize-args.js"));
|
|
52
|
+
var _resolveExternalJs = /*#__PURE__*/ _interopRequireDefault(require("./resolve-external.js"));
|
|
53
|
+
var _bundleJs = /*#__PURE__*/ _interopRequireDefault(require("./bundle.js"));
|
|
54
|
+
var _dereferenceJs = /*#__PURE__*/ _interopRequireDefault(require("./dereference.js"));
|
|
55
|
+
var _urlJs = /*#__PURE__*/ _interopRequireWildcard(require("./util/url.js"));
|
|
56
|
+
var _errorsJs = require("./util/errors.js");
|
|
57
|
+
var _callMeMaybe = /*#__PURE__*/ _interopRequireDefault(require("call-me-maybe"));
|
|
58
|
+
var _ono = require("@jsdevtools/ono");
|
|
59
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
60
|
+
try {
|
|
61
|
+
var info = gen[key](arg);
|
|
62
|
+
var value = info.value;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (info.done) {
|
|
68
|
+
resolve(value);
|
|
69
|
+
} else {
|
|
70
|
+
Promise.resolve(value).then(_next, _throw);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function _asyncToGenerator(fn) {
|
|
74
|
+
return function() {
|
|
75
|
+
var self = this, args = arguments;
|
|
76
|
+
return new Promise(function(resolve, reject) {
|
|
77
|
+
var gen = fn.apply(self, args);
|
|
78
|
+
function _next(value) {
|
|
79
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
80
|
+
}
|
|
81
|
+
function _throw(err) {
|
|
82
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
83
|
+
}
|
|
84
|
+
_next(undefined);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function _interopRequireDefault(obj) {
|
|
89
|
+
return obj && obj.__esModule ? obj : {
|
|
90
|
+
default: obj
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
94
|
+
if (typeof WeakMap !== "function") return null;
|
|
95
|
+
var cacheBabelInterop = new WeakMap();
|
|
96
|
+
var cacheNodeInterop = new WeakMap();
|
|
97
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
98
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
99
|
+
})(nodeInterop);
|
|
100
|
+
}
|
|
101
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
102
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
103
|
+
return obj;
|
|
104
|
+
}
|
|
105
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
106
|
+
return {
|
|
107
|
+
default: obj
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
111
|
+
if (cache && cache.has(obj)) {
|
|
112
|
+
return cache.get(obj);
|
|
113
|
+
}
|
|
114
|
+
var newObj = {};
|
|
115
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
116
|
+
for(var key in obj){
|
|
117
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
118
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
119
|
+
if (desc && (desc.get || desc.set)) {
|
|
120
|
+
Object.defineProperty(newObj, key, desc);
|
|
121
|
+
} else {
|
|
122
|
+
newObj[key] = obj[key];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
newObj.default = obj;
|
|
127
|
+
if (cache) {
|
|
128
|
+
cache.set(obj, newObj);
|
|
129
|
+
}
|
|
130
|
+
return newObj;
|
|
131
|
+
}
|
|
132
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
133
|
+
var f, y, t, g, _ = {
|
|
134
|
+
label: 0,
|
|
135
|
+
sent: function() {
|
|
136
|
+
if (t[0] & 1) throw t[1];
|
|
137
|
+
return t[1];
|
|
138
|
+
},
|
|
139
|
+
trys: [],
|
|
140
|
+
ops: []
|
|
141
|
+
};
|
|
142
|
+
return(g = {
|
|
143
|
+
next: verb(0),
|
|
144
|
+
"throw": verb(1),
|
|
145
|
+
"return": verb(2)
|
|
146
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
147
|
+
return this;
|
|
148
|
+
}), g);
|
|
149
|
+
function verb(n) {
|
|
150
|
+
return function(v) {
|
|
151
|
+
return step([
|
|
152
|
+
n,
|
|
153
|
+
v
|
|
154
|
+
]);
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function step(op) {
|
|
158
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
159
|
+
while(_)try {
|
|
160
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
161
|
+
if (y = 0, t) op = [
|
|
162
|
+
op[0] & 2,
|
|
163
|
+
t.value
|
|
164
|
+
];
|
|
165
|
+
switch(op[0]){
|
|
166
|
+
case 0:
|
|
167
|
+
case 1:
|
|
168
|
+
t = op;
|
|
169
|
+
break;
|
|
170
|
+
case 4:
|
|
171
|
+
_.label++;
|
|
172
|
+
return {
|
|
173
|
+
value: op[1],
|
|
174
|
+
done: false
|
|
175
|
+
};
|
|
176
|
+
case 5:
|
|
177
|
+
_.label++;
|
|
178
|
+
y = op[1];
|
|
179
|
+
op = [
|
|
180
|
+
0
|
|
181
|
+
];
|
|
182
|
+
continue;
|
|
183
|
+
case 7:
|
|
184
|
+
op = _.ops.pop();
|
|
185
|
+
_.trys.pop();
|
|
186
|
+
continue;
|
|
187
|
+
default:
|
|
188
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
189
|
+
_ = 0;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
193
|
+
_.label = op[1];
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
197
|
+
_.label = t[1];
|
|
198
|
+
t = op;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
if (t && _.label < t[2]) {
|
|
202
|
+
_.label = t[2];
|
|
203
|
+
_.ops.push(op);
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
if (t[2]) _.ops.pop();
|
|
207
|
+
_.trys.pop();
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
op = body.call(thisArg, _);
|
|
211
|
+
} catch (e) {
|
|
212
|
+
op = [
|
|
213
|
+
6,
|
|
214
|
+
e
|
|
215
|
+
];
|
|
216
|
+
y = 0;
|
|
217
|
+
} finally{
|
|
218
|
+
f = t = 0;
|
|
219
|
+
}
|
|
220
|
+
if (op[0] & 5) throw op[1];
|
|
221
|
+
return {
|
|
222
|
+
value: op[0] ? op[1] : void 0,
|
|
223
|
+
done: true
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var _default = $RefParser;
|
|
228
|
+
/**
|
|
229
|
+
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
|
230
|
+
* and provides methods for traversing, manipulating, and dereferencing those references.
|
|
231
|
+
*
|
|
232
|
+
* @constructor
|
|
233
|
+
*/ function $RefParser() {
|
|
234
|
+
/**
|
|
235
|
+
* The parsed (and possibly dereferenced) JSON schema object
|
|
236
|
+
*
|
|
237
|
+
* @type {object}
|
|
238
|
+
* @readonly
|
|
239
|
+
*/ this.schema = null;
|
|
240
|
+
/**
|
|
241
|
+
* The resolved JSON references
|
|
242
|
+
*
|
|
243
|
+
* @type {$Refs}
|
|
244
|
+
* @readonly
|
|
245
|
+
*/ this.$refs = new _refsJs.default();
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Parses the given JSON schema.
|
|
249
|
+
* This method does not resolve any JSON references.
|
|
250
|
+
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
253
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
254
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
|
|
255
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
|
256
|
+
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
|
|
257
|
+
*/ $RefParser.parse = function parse(path, schema, options, callback) {
|
|
258
|
+
var Class = this; // eslint-disable-line consistent-this
|
|
259
|
+
var instance = new Class();
|
|
260
|
+
return instance.parse.apply(instance, arguments);
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Parses the given JSON schema.
|
|
264
|
+
* This method does not resolve any JSON references.
|
|
265
|
+
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
|
266
|
+
*
|
|
267
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
268
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
269
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
|
|
270
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
|
271
|
+
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
|
|
272
|
+
*/ $RefParser.prototype.parse = function() {
|
|
273
|
+
var _parse = _asyncToGenerator(function(path, schema, options, callback) {
|
|
274
|
+
var args, promise, _$err, pathType, $ref, me, result, err;
|
|
275
|
+
var _arguments = arguments;
|
|
276
|
+
return __generator(this, function(_state) {
|
|
277
|
+
switch(_state.label){
|
|
278
|
+
case 0:
|
|
279
|
+
args = (0, _normalizeArgsJs.default)(_arguments);
|
|
280
|
+
if (!args.path && !args.schema) {
|
|
281
|
+
_$err = (0, _ono.ono)("Expected a file path, URL, or object. Got ".concat(args.path || args.schema));
|
|
282
|
+
return [
|
|
283
|
+
2,
|
|
284
|
+
(0, _callMeMaybe.default)(args.callback, Promise.reject(_$err))
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
// Reset everything
|
|
288
|
+
this.schema = null;
|
|
289
|
+
this.$refs = new _refsJs.default();
|
|
290
|
+
pathType = "http";
|
|
291
|
+
if (_urlJs.isFileSystemPath(args.path)) {
|
|
292
|
+
args.path = _urlJs.fromFileSystemPath(args.path);
|
|
293
|
+
pathType = "file";
|
|
294
|
+
}
|
|
295
|
+
// Resolve the absolute path of the schema
|
|
296
|
+
args.path = _urlJs.resolve(_urlJs.cwd(), args.path);
|
|
297
|
+
if (args.schema && typeof args.schema === "object") {
|
|
298
|
+
$ref = this.$refs._add(args.path);
|
|
299
|
+
$ref.value = args.schema;
|
|
300
|
+
$ref.pathType = pathType;
|
|
301
|
+
promise = Promise.resolve(args.schema);
|
|
302
|
+
} else {
|
|
303
|
+
// Parse the schema file/url
|
|
304
|
+
promise = (0, _parseJs.default)(args.path, this.$refs, args.options);
|
|
305
|
+
}
|
|
306
|
+
me = this;
|
|
307
|
+
_state.label = 1;
|
|
308
|
+
case 1:
|
|
309
|
+
_state.trys.push([
|
|
310
|
+
1,
|
|
311
|
+
3,
|
|
312
|
+
,
|
|
313
|
+
4
|
|
314
|
+
]);
|
|
315
|
+
return [
|
|
316
|
+
4,
|
|
317
|
+
promise
|
|
318
|
+
];
|
|
319
|
+
case 2:
|
|
320
|
+
result = _state.sent();
|
|
321
|
+
if (result !== null && typeof result === "object" && !Buffer.isBuffer(result)) {
|
|
322
|
+
me.schema = result;
|
|
323
|
+
return [
|
|
324
|
+
2,
|
|
325
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(me.schema))
|
|
326
|
+
];
|
|
327
|
+
} else if (args.options.continueOnError) {
|
|
328
|
+
me.schema = null; // it's already set to null at line 79, but let's set it again for the sake of readability
|
|
329
|
+
return [
|
|
330
|
+
2,
|
|
331
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(me.schema))
|
|
332
|
+
];
|
|
333
|
+
} else {
|
|
334
|
+
throw _ono.ono.syntax('"'.concat(me.$refs._root$Ref.path || result, '" is not a valid JSON Schema'));
|
|
335
|
+
}
|
|
336
|
+
return [
|
|
337
|
+
3,
|
|
338
|
+
4
|
|
339
|
+
];
|
|
340
|
+
case 3:
|
|
341
|
+
err = _state.sent();
|
|
342
|
+
if (!args.options.continueOnError || !(0, _errorsJs.isHandledError)(err)) {
|
|
343
|
+
return [
|
|
344
|
+
2,
|
|
345
|
+
(0, _callMeMaybe.default)(args.callback, Promise.reject(err))
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
if (this.$refs._$refs[_urlJs.stripHash(args.path)]) {
|
|
349
|
+
this.$refs._$refs[_urlJs.stripHash(args.path)].addError(err);
|
|
350
|
+
}
|
|
351
|
+
return [
|
|
352
|
+
2,
|
|
353
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(null))
|
|
354
|
+
];
|
|
355
|
+
case 4:
|
|
356
|
+
return [
|
|
357
|
+
2
|
|
358
|
+
];
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
function parse(path, schema, options, callback) {
|
|
363
|
+
return _parse.apply(this, arguments);
|
|
364
|
+
}
|
|
365
|
+
return parse;
|
|
366
|
+
}();
|
|
367
|
+
/**
|
|
368
|
+
* Parses the given JSON schema and resolves any JSON references, including references in
|
|
369
|
+
* externally-referenced files.
|
|
370
|
+
*
|
|
371
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
372
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
373
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
|
|
374
|
+
* @param {function} [callback]
|
|
375
|
+
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
|
376
|
+
*
|
|
377
|
+
* @returns {Promise}
|
|
378
|
+
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
|
379
|
+
*/ $RefParser.resolve = function resolve(path, schema, options, callback) {
|
|
380
|
+
var Class = this; // eslint-disable-line consistent-this
|
|
381
|
+
var instance = new Class();
|
|
382
|
+
return instance.resolve.apply(instance, arguments);
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Parses the given JSON schema and resolves any JSON references, including references in
|
|
386
|
+
* externally-referenced files.
|
|
387
|
+
*
|
|
388
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
389
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
390
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
|
|
391
|
+
* @param {function} [callback]
|
|
392
|
+
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
|
393
|
+
*
|
|
394
|
+
* @returns {Promise}
|
|
395
|
+
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
|
396
|
+
*/ $RefParser.prototype.resolve = function() {
|
|
397
|
+
var _resolve = _asyncToGenerator(function(path, schema, options, callback) {
|
|
398
|
+
var me, args, err;
|
|
399
|
+
var _arguments = arguments;
|
|
400
|
+
return __generator(this, function(_state) {
|
|
401
|
+
switch(_state.label){
|
|
402
|
+
case 0:
|
|
403
|
+
me = this;
|
|
404
|
+
args = (0, _normalizeArgsJs.default)(_arguments);
|
|
405
|
+
_state.label = 1;
|
|
406
|
+
case 1:
|
|
407
|
+
_state.trys.push([
|
|
408
|
+
1,
|
|
409
|
+
4,
|
|
410
|
+
,
|
|
411
|
+
5
|
|
412
|
+
]);
|
|
413
|
+
return [
|
|
414
|
+
4,
|
|
415
|
+
this.parse(args.path, args.schema, args.options)
|
|
416
|
+
];
|
|
417
|
+
case 2:
|
|
418
|
+
_state.sent();
|
|
419
|
+
return [
|
|
420
|
+
4,
|
|
421
|
+
(0, _resolveExternalJs.default)(me, args.options)
|
|
422
|
+
];
|
|
423
|
+
case 3:
|
|
424
|
+
_state.sent();
|
|
425
|
+
finalize(me);
|
|
426
|
+
return [
|
|
427
|
+
2,
|
|
428
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(me.$refs))
|
|
429
|
+
];
|
|
430
|
+
case 4:
|
|
431
|
+
err = _state.sent();
|
|
432
|
+
return [
|
|
433
|
+
2,
|
|
434
|
+
(0, _callMeMaybe.default)(args.callback, Promise.reject(err))
|
|
435
|
+
];
|
|
436
|
+
case 5:
|
|
437
|
+
return [
|
|
438
|
+
2
|
|
439
|
+
];
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
function resolve(path, schema, options, callback) {
|
|
444
|
+
return _resolve.apply(this, arguments);
|
|
445
|
+
}
|
|
446
|
+
return resolve;
|
|
447
|
+
}();
|
|
448
|
+
/**
|
|
449
|
+
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
450
|
+
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
451
|
+
* not any *external* references.
|
|
452
|
+
*
|
|
453
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
454
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
455
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
456
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
457
|
+
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
|
|
458
|
+
*/ $RefParser.bundle = function bundle(path, schema, options, callback) {
|
|
459
|
+
var Class = this; // eslint-disable-line consistent-this
|
|
460
|
+
var instance = new Class();
|
|
461
|
+
return instance.bundle.apply(instance, arguments);
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
465
|
+
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
466
|
+
* not any *external* references.
|
|
467
|
+
*
|
|
468
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
469
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
470
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
471
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
472
|
+
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
|
|
473
|
+
*/ $RefParser.prototype.bundle = function() {
|
|
474
|
+
var _bundle = _asyncToGenerator(function(path, schema, options, callback) {
|
|
475
|
+
var me, args, err;
|
|
476
|
+
var _arguments = arguments;
|
|
477
|
+
return __generator(this, function(_state) {
|
|
478
|
+
switch(_state.label){
|
|
479
|
+
case 0:
|
|
480
|
+
me = this;
|
|
481
|
+
args = (0, _normalizeArgsJs.default)(_arguments);
|
|
482
|
+
_state.label = 1;
|
|
483
|
+
case 1:
|
|
484
|
+
_state.trys.push([
|
|
485
|
+
1,
|
|
486
|
+
3,
|
|
487
|
+
,
|
|
488
|
+
4
|
|
489
|
+
]);
|
|
490
|
+
return [
|
|
491
|
+
4,
|
|
492
|
+
this.resolve(args.path, args.schema, args.options)
|
|
493
|
+
];
|
|
494
|
+
case 2:
|
|
495
|
+
_state.sent();
|
|
496
|
+
(0, _bundleJs.default)(me, args.options);
|
|
497
|
+
finalize(me);
|
|
498
|
+
return [
|
|
499
|
+
2,
|
|
500
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(me.schema))
|
|
501
|
+
];
|
|
502
|
+
case 3:
|
|
503
|
+
err = _state.sent();
|
|
504
|
+
return [
|
|
505
|
+
2,
|
|
506
|
+
(0, _callMeMaybe.default)(args.callback, Promise.reject(err))
|
|
507
|
+
];
|
|
508
|
+
case 4:
|
|
509
|
+
return [
|
|
510
|
+
2
|
|
511
|
+
];
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
function bundle(path, schema, options, callback) {
|
|
516
|
+
return _bundle.apply(this, arguments);
|
|
517
|
+
}
|
|
518
|
+
return bundle;
|
|
519
|
+
}();
|
|
520
|
+
/**
|
|
521
|
+
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
522
|
+
* That is, all JSON references are replaced with their resolved values.
|
|
523
|
+
*
|
|
524
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
525
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
526
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
527
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
528
|
+
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
|
|
529
|
+
*/ $RefParser.dereference = function dereference(path, schema, options, callback) {
|
|
530
|
+
var Class = this; // eslint-disable-line consistent-this
|
|
531
|
+
var instance = new Class();
|
|
532
|
+
return instance.dereference.apply(instance, arguments);
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
536
|
+
* That is, all JSON references are replaced with their resolved values.
|
|
537
|
+
*
|
|
538
|
+
* @param {string} [path] - The file path or URL of the JSON schema
|
|
539
|
+
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
540
|
+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
541
|
+
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
542
|
+
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
|
|
543
|
+
*/ $RefParser.prototype.dereference = function() {
|
|
544
|
+
var _dereference = _asyncToGenerator(function(path, schema, options, callback) {
|
|
545
|
+
var me, args, err;
|
|
546
|
+
var _arguments = arguments;
|
|
547
|
+
return __generator(this, function(_state) {
|
|
548
|
+
switch(_state.label){
|
|
549
|
+
case 0:
|
|
550
|
+
me = this;
|
|
551
|
+
args = (0, _normalizeArgsJs.default)(_arguments);
|
|
552
|
+
_state.label = 1;
|
|
553
|
+
case 1:
|
|
554
|
+
_state.trys.push([
|
|
555
|
+
1,
|
|
556
|
+
3,
|
|
557
|
+
,
|
|
558
|
+
4
|
|
559
|
+
]);
|
|
560
|
+
return [
|
|
561
|
+
4,
|
|
562
|
+
this.resolve(args.path, args.schema, args.options)
|
|
563
|
+
];
|
|
564
|
+
case 2:
|
|
565
|
+
_state.sent();
|
|
566
|
+
(0, _dereferenceJs.default)(me, args.options);
|
|
567
|
+
finalize(me);
|
|
568
|
+
return [
|
|
569
|
+
2,
|
|
570
|
+
(0, _callMeMaybe.default)(args.callback, Promise.resolve(me.schema))
|
|
571
|
+
];
|
|
572
|
+
case 3:
|
|
573
|
+
err = _state.sent();
|
|
574
|
+
return [
|
|
575
|
+
2,
|
|
576
|
+
(0, _callMeMaybe.default)(args.callback, Promise.reject(err))
|
|
577
|
+
];
|
|
578
|
+
case 4:
|
|
579
|
+
return [
|
|
580
|
+
2
|
|
581
|
+
];
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
function dereference(path, schema, options, callback) {
|
|
586
|
+
return _dereference.apply(this, arguments);
|
|
587
|
+
}
|
|
588
|
+
return dereference;
|
|
589
|
+
}();
|
|
590
|
+
function finalize(parser) {
|
|
591
|
+
var errors = _errorsJs.JSONParserErrorGroup.getParserErrors(parser);
|
|
592
|
+
if (errors.length > 0) {
|
|
593
|
+
throw new _errorsJs.JSONParserErrorGroup(parser);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
var parse = $RefParser.parse.bind($RefParser);
|
|
597
|
+
var resolve = $RefParser.resolve.bind($RefParser);
|
|
598
|
+
var bundle = $RefParser.bundle.bind($RefParser);
|
|
599
|
+
var dereference = $RefParser.dereference.bind($RefParser);
|
|
600
|
+
// CommonJS default export hack
|
|
601
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
602
|
+
module.exports = Object.assign(module.exports.default, module.exports);
|
|
603
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _optionsJs = /*#__PURE__*/ _interopRequireDefault(require("./options.js"));
|
|
12
|
+
function _instanceof(left, right) {
|
|
13
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
14
|
+
return !!right[Symbol.hasInstance](left);
|
|
15
|
+
} else {
|
|
16
|
+
return left instanceof right;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _interopRequireDefault(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var _default = normalizeArgs;
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes the given arguments, accounting for optional args.
|
|
27
|
+
*
|
|
28
|
+
* @param {Arguments} args
|
|
29
|
+
* @returns {object}
|
|
30
|
+
*/ function normalizeArgs(args) {
|
|
31
|
+
var path, schema, options, callback;
|
|
32
|
+
args = Array.prototype.slice.call(args);
|
|
33
|
+
if (typeof args[args.length - 1] === "function") {
|
|
34
|
+
// The last parameter is a callback function
|
|
35
|
+
callback = args.pop();
|
|
36
|
+
}
|
|
37
|
+
if (typeof args[0] === "string") {
|
|
38
|
+
// The first parameter is the path
|
|
39
|
+
path = args[0];
|
|
40
|
+
if (typeof args[2] === "object") {
|
|
41
|
+
// The second parameter is the schema, and the third parameter is the options
|
|
42
|
+
schema = args[1];
|
|
43
|
+
options = args[2];
|
|
44
|
+
} else {
|
|
45
|
+
// The second parameter is the options
|
|
46
|
+
schema = undefined;
|
|
47
|
+
options = args[1];
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
// The first parameter is the schema
|
|
51
|
+
path = "";
|
|
52
|
+
schema = args[0];
|
|
53
|
+
options = args[1];
|
|
54
|
+
}
|
|
55
|
+
if (!_instanceof(options, _optionsJs.default)) {
|
|
56
|
+
options = new _optionsJs.default(options);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
path: path,
|
|
60
|
+
schema: schema,
|
|
61
|
+
options: options,
|
|
62
|
+
callback: callback
|
|
63
|
+
};
|
|
64
|
+
}
|