@hey-api/json-schema-ref-parser 1.3.1 → 1.4.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/dist/index.mjs CHANGED
@@ -1,19 +1,16 @@
1
1
  import { Ono, ono } from "@jsdevtools/ono";
2
2
  import { join, win32 } from "node:path";
3
- import yaml, { JSON_SCHEMA } from "js-yaml";
3
+ import { parse } from "yaml";
4
4
  import fs from "fs";
5
-
6
5
  //#region src/util/convert-path-to-posix.ts
7
6
  function convertPathToPosix(filePath) {
8
7
  if (filePath.startsWith("\\\\?\\")) return filePath;
9
8
  return filePath.replaceAll("\\", "/");
10
9
  }
11
-
12
10
  //#endregion
13
11
  //#region src/util/is-windows.ts
14
12
  const isWindowsConst = /^win/.test(globalThis.process ? globalThis.process.platform : "");
15
13
  const isWindows = () => isWindowsConst;
16
-
17
14
  //#endregion
18
15
  //#region src/util/url.ts
19
16
  const forwardSlashPattern = /\//g;
@@ -181,7 +178,6 @@ function toFileSystemPath(path, keepFileProtocol) {
181
178
  }
182
179
  return path;
183
180
  }
184
-
185
181
  //#endregion
186
182
  //#region src/util/errors.ts
187
183
  var JSONParserError = class extends Error {
@@ -228,6 +224,13 @@ var ParserError = class extends JSONParserError {
228
224
  super(`Error parsing ${source}: ${message}`, source);
229
225
  }
230
226
  };
227
+ var UnmatchedParserError = class extends JSONParserError {
228
+ code = "EUNMATCHEDPARSER";
229
+ name = "UnmatchedParserError";
230
+ constructor(source) {
231
+ super(`Could not find parser for "${source}"`, source);
232
+ }
233
+ };
231
234
  var ResolverError = class extends JSONParserError {
232
235
  code = "ERESOLVER";
233
236
  name = "ResolverError";
@@ -237,6 +240,13 @@ var ResolverError = class extends JSONParserError {
237
240
  if ("code" in ex) this.ioErrorCode = String(ex.code);
238
241
  }
239
242
  };
243
+ var UnmatchedResolverError = class extends JSONParserError {
244
+ code = "EUNMATCHEDRESOLVER";
245
+ name = "UnmatchedResolverError";
246
+ constructor(source) {
247
+ super(`Could not find resolver for "${source}"`, source);
248
+ }
249
+ };
240
250
  var MissingPointerError = class extends JSONParserError {
241
251
  code = "EMISSINGPOINTER";
242
252
  name = "MissingPointerError";
@@ -244,6 +254,13 @@ var MissingPointerError = class extends JSONParserError {
244
254
  super(`Missing $ref pointer "${getHash(path)}". Token "${token}" does not exist.`, stripHash(path));
245
255
  }
246
256
  };
257
+ var TimeoutError = class extends JSONParserError {
258
+ code = "ETIMEOUT";
259
+ name = "TimeoutError";
260
+ constructor(timeout) {
261
+ super(`Dereferencing timeout reached: ${timeout}ms`);
262
+ }
263
+ };
247
264
  var InvalidPointerError = class extends JSONParserError {
248
265
  code = "EUNMATCHEDRESOLVER";
249
266
  name = "InvalidPointerError";
@@ -258,7 +275,6 @@ function normalizeError(err) {
258
275
  if (err.path === null) err.path = [];
259
276
  return err;
260
277
  }
261
-
262
278
  //#endregion
263
279
  //#region src/ref.ts
264
280
  /**
@@ -292,7 +308,7 @@ var $Ref = class $Ref {
292
308
  */
293
309
  $refs;
294
310
  /**
295
- * Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
311
+ * Indicates the type of {@link $Ref#path} (e.g., "file", "http", etc.)
296
312
  */
297
313
  pathType;
298
314
  /**
@@ -349,7 +365,7 @@ var $Ref = class $Ref {
349
365
  * @returns
350
366
  */
351
367
  resolve(path, options, friendlyPath, pathFromRoot) {
352
- return new pointer_default(this, path, friendlyPath).resolve(this.value, options, pathFromRoot);
368
+ return new Pointer(this, path, friendlyPath).resolve(this.value, options, pathFromRoot);
353
369
  }
354
370
  /**
355
371
  * Sets the value of a nested property within this {@link $Ref#value}.
@@ -359,7 +375,7 @@ var $Ref = class $Ref {
359
375
  * @param value - The value to assign
360
376
  */
361
377
  set(path, value) {
362
- this.value = new pointer_default(this, path).set(this.value, value);
378
+ this.value = new Pointer(this, path).set(this.value, value);
363
379
  }
364
380
  /**
365
381
  * Determines whether the given value is a JSON reference.
@@ -368,7 +384,7 @@ var $Ref = class $Ref {
368
384
  * @returns
369
385
  */
370
386
  static is$Ref(value) {
371
- return Boolean(value) && typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string" && value.$ref.length > 0;
387
+ return Boolean(value) && typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string" && Boolean(value.$ref.length);
372
388
  }
373
389
  /**
374
390
  * Determines whether the given value is an external JSON reference.
@@ -469,8 +485,6 @@ var $Ref = class $Ref {
469
485
  } else return resolvedValue;
470
486
  }
471
487
  };
472
- var ref_default = $Ref;
473
-
474
488
  //#endregion
475
489
  //#region src/pointer.ts
476
490
  const slashes = /\//g;
@@ -565,7 +579,7 @@ var Pointer = class Pointer {
565
579
  errors.push(new MissingPointerError(token, decodeURI(this.originalPath)));
566
580
  } else this.value = this.value[token];
567
581
  }
568
- if (errors.length > 0) throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Multiple missing pointer errors");
582
+ if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Multiple missing pointer errors");
569
583
  if (!this.value || this.value.$ref && resolve(this.path, this.value.$ref) !== pathFromRoot) resolveIf$Ref(this, options, pathFromRoot);
570
584
  return this;
571
585
  }
@@ -582,7 +596,7 @@ var Pointer = class Pointer {
582
596
  set(obj, value, options) {
583
597
  const tokens = Pointer.parse(this.path);
584
598
  let token;
585
- if (tokens.length === 0) {
599
+ if (!tokens.length) {
586
600
  this.value = value;
587
601
  return value;
588
602
  }
@@ -601,7 +615,7 @@ var Pointer = class Pointer {
601
615
  /**
602
616
  * Parses a JSON pointer (or a path containing a JSON pointer in the hash)
603
617
  * and returns an array of the pointer's tokens.
604
- * (e.g. "schema.json#/definitions/person/name" => ["definitions", "person", "name"])
618
+ * (e.g., "schema.json#/definitions/person/name" => ["definitions", "person", "name"])
605
619
  *
606
620
  * The pointer is parsed according to RFC 6901
607
621
  * {@link https://tools.ietf.org/html/rfc6901#section-3}
@@ -621,8 +635,8 @@ var Pointer = class Pointer {
621
635
  /**
622
636
  * Creates a JSON pointer path, by joining one or more tokens to a base path.
623
637
  *
624
- * @param base - The base path (e.g. "schema.json#/definitions/person")
625
- * @param tokens - The token(s) to append (e.g. ["name", "first"])
638
+ * @param base - The base path (e.g., "schema.json#/definitions/person")
639
+ * @param tokens - The token(s) to append (e.g., ["name", "first"])
626
640
  * @returns
627
641
  */
628
642
  static join(base, tokens) {
@@ -647,15 +661,15 @@ var Pointer = class Pointer {
647
661
  * @returns - Returns `true` if the resolution path changed
648
662
  */
649
663
  function resolveIf$Ref(pointer, options, pathFromRoot) {
650
- if (ref_default.isAllowed$Ref(pointer.value)) {
664
+ if ($Ref.isAllowed$Ref(pointer.value)) {
651
665
  const $refPath = resolve(pointer.path, pointer.value.$ref);
652
666
  if ($refPath === pointer.path && !isRootPath(pathFromRoot)) pointer.circular = true;
653
667
  else {
654
668
  const resolved = pointer.$ref.$refs._resolve($refPath, pointer.path, options);
655
669
  if (resolved === null) return false;
656
670
  pointer.indirections += resolved.indirections + 1;
657
- if (ref_default.isExtended$Ref(pointer.value)) {
658
- pointer.value = ref_default.dereference(pointer.value, resolved.value);
671
+ if ($Ref.isExtended$Ref(pointer.value)) {
672
+ pointer.value = $Ref.dereference(pointer.value, resolved.value);
659
673
  return false;
660
674
  } else {
661
675
  pointer.$ref = resolved.$ref;
@@ -666,7 +680,6 @@ function resolveIf$Ref(pointer, options, pathFromRoot) {
666
680
  }
667
681
  }
668
682
  }
669
- var pointer_default = Pointer;
670
683
  /**
671
684
  * Sets the specified token value of the {@link Pointer#value}.
672
685
  *
@@ -691,7 +704,6 @@ function unwrapOrThrow(value) {
691
704
  function isRootPath(pathFromRoot) {
692
705
  return typeof pathFromRoot == "string" && Pointer.parse(pathFromRoot).length == 0;
693
706
  }
694
-
695
707
  //#endregion
696
708
  //#region src/bundle.ts
697
709
  /**
@@ -729,7 +741,7 @@ const createInventoryLookup = () => {
729
741
  * @returns The container type: "schemas", "parameters", "requestBodies", "responses", or "headers"
730
742
  */
731
743
  const getContainerTypeFromPath = (path) => {
732
- const tokens = pointer_default.parse(path);
744
+ const tokens = Pointer.parse(path);
733
745
  const has = (t) => tokens.includes(t);
734
746
  if (has("parameters")) return "parameters";
735
747
  if (has("requestBody")) return "requestBodies";
@@ -739,7 +751,7 @@ const getContainerTypeFromPath = (path) => {
739
751
  return "schemas";
740
752
  };
741
753
  /**
742
- * Inventories the given JSON Reference (i.e. records detailed information about it so we can
754
+ * Inventories the given JSON Reference (i.e., records detailed information about it so we can
743
755
  * optimize all $refs in the schema), and then crawls the resolved value.
744
756
  */
745
757
  const inventory$Ref = ({ $refKey, $refParent, $refs, indirections, inventory, inventoryLookup, options, path, pathFromRoot, resolvedRefs = /* @__PURE__ */ new Map(), visitedObjects = /* @__PURE__ */ new WeakSet() }) => {
@@ -751,13 +763,13 @@ const inventory$Ref = ({ $refKey, $refParent, $refs, indirections, inventory, in
751
763
  pointer = $refs._resolve($refPath, pathFromRoot, options);
752
764
  } catch (error) {
753
765
  if (error instanceof MissingPointerError) {
754
- const hash$1 = getHash($refPath);
755
- if (hash$1) {
766
+ const hash = getHash($refPath);
767
+ if (hash) {
756
768
  const baseFile = stripHash($refPath);
757
769
  for (const filePath of Object.keys($refs._$refs)) {
758
770
  if (filePath === baseFile) continue;
759
771
  try {
760
- pointer = $refs._resolve(filePath + hash$1, pathFromRoot, options);
772
+ pointer = $refs._resolve(filePath + hash, pathFromRoot, options);
761
773
  if (pointer) break;
762
774
  } catch {}
763
775
  }
@@ -771,11 +783,11 @@ const inventory$Ref = ({ $refKey, $refParent, $refs, indirections, inventory, in
771
783
  if (pointer) resolvedRefs.set($refPath, pointer);
772
784
  }
773
785
  if (pointer === null) return;
774
- const depth = pointer_default.parse(pathFromRoot).length;
786
+ const depth = Pointer.parse(pathFromRoot).length;
775
787
  const file = stripHash(pointer.path);
776
788
  const hash = getHash(pointer.path);
777
789
  const external = file !== $refs._root$Ref.path;
778
- const extended = ref_default.isExtended$Ref($ref);
790
+ const extended = $Ref.isExtended$Ref($ref);
779
791
  indirections += pointer.indirections;
780
792
  const existingEntry = inventoryLookup.find($refParent, $refKey);
781
793
  if (existingEntry && existingEntry.pathFromRoot === pathFromRoot) if (depth < existingEntry.depth || indirections < existingEntry.indirections) {
@@ -824,7 +836,7 @@ const crawl$1 = ({ $refs, indirections, inventory, inventoryLookup, key, options
824
836
  const obj = key === null ? parent : parent[key];
825
837
  if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
826
838
  if (visitedObjects.has(obj)) return;
827
- if (ref_default.isAllowed$Ref(obj)) inventory$Ref({
839
+ if ($Ref.isAllowed$Ref(obj)) inventory$Ref({
828
840
  $refKey: key,
829
841
  $refParent: parent,
830
842
  $refs,
@@ -844,12 +856,12 @@ const crawl$1 = ({ $refs, indirections, inventory, inventoryLookup, key, options
844
856
  else if (b === "definitions") return 1;
845
857
  else return a.length - b.length;
846
858
  });
847
- for (const key$1 of keys) {
848
- const keyPath = pointer_default.join(path, key$1);
849
- const keyPathFromRoot = pointer_default.join(pathFromRoot, key$1);
850
- const value = obj[key$1];
851
- if (ref_default.isAllowed$Ref(value)) inventory$Ref({
852
- $refKey: key$1,
859
+ for (const key of keys) {
860
+ const keyPath = Pointer.join(path, key);
861
+ const keyPathFromRoot = Pointer.join(pathFromRoot, key);
862
+ const value = obj[key];
863
+ if ($Ref.isAllowed$Ref(value)) inventory$Ref({
864
+ $refKey: key,
853
865
  $refParent: obj,
854
866
  $refs,
855
867
  indirections,
@@ -866,7 +878,7 @@ const crawl$1 = ({ $refs, indirections, inventory, inventoryLookup, key, options
866
878
  indirections,
867
879
  inventory,
868
880
  inventoryLookup,
869
- key: key$1,
881
+ key,
870
882
  options,
871
883
  parent: obj,
872
884
  path: keyPath,
@@ -899,8 +911,8 @@ function remap(parser, inventory) {
899
911
  }
900
912
  });
901
913
  const ensureContainer = (type) => {
902
- const isOas3 = !!(root && typeof root === "object" && typeof root.openapi === "string");
903
- const isOas2 = !!(root && typeof root === "object" && typeof root.swagger === "string");
914
+ const isOas3 = Boolean(root && typeof root === "object" && typeof root.openapi === "string");
915
+ const isOas2 = Boolean(root && typeof root === "object" && typeof root.swagger === "string");
904
916
  if (isOas3) {
905
917
  if (!root.components || typeof root.components !== "object") root.components = {};
906
918
  if (!root.components[type] || typeof root.components[type] !== "object") root.components[type] = {};
@@ -1003,11 +1015,11 @@ function remap(parser, inventory) {
1003
1015
  for (const entry of inventory) {
1004
1016
  if (!entry || !entry.$ref || typeof entry.$ref !== "object") continue;
1005
1017
  if (!entry.external) {
1006
- if (!entry.extended && entry.$ref && typeof entry.$ref === "object") entry.$ref.$ref = entry.hash;
1018
+ if (!entry.extended && entry.$ref && typeof entry.$ref === "object") entry.$ref.$ref = decodeURI(entry.hash);
1007
1019
  continue;
1008
1020
  }
1009
1021
  if (entry.circular) {
1010
- if (entry.$ref && typeof entry.$ref === "object") entry.$ref.$ref = entry.pathFromRoot;
1022
+ if (entry.$ref && typeof entry.$ref === "object") entry.$ref.$ref = decodeURI(entry.pathFromRoot);
1011
1023
  continue;
1012
1024
  }
1013
1025
  const { obj: container, prefix } = ensureContainer(chooseComponent(entry));
@@ -1070,7 +1082,6 @@ function bundle(parser, options) {
1070
1082
  });
1071
1083
  remap(parser, inventory);
1072
1084
  }
1073
-
1074
1085
  //#endregion
1075
1086
  //#region src/parsers/binary.ts
1076
1087
  const BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
@@ -1079,7 +1090,6 @@ const binaryParser = {
1079
1090
  handler: (file) => Buffer.isBuffer(file.data) ? file.data : Buffer.from(file.data),
1080
1091
  name: "binary"
1081
1092
  };
1082
-
1083
1093
  //#endregion
1084
1094
  //#region src/parsers/json.ts
1085
1095
  const jsonParser = {
@@ -1096,14 +1106,13 @@ const jsonParser = {
1096
1106
  const firstCurlyBrace = data.indexOf("{");
1097
1107
  data = data.slice(firstCurlyBrace);
1098
1108
  return JSON.parse(data);
1099
- } catch (error$1) {
1100
- throw new ParserError(error$1.message, file.url);
1109
+ } catch (error) {
1110
+ throw new ParserError(error.message, file.url);
1101
1111
  }
1102
1112
  }
1103
1113
  },
1104
1114
  name: "json"
1105
1115
  };
1106
-
1107
1116
  //#endregion
1108
1117
  //#region src/parsers/text.ts
1109
1118
  const TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
@@ -1116,7 +1125,6 @@ const textParser = {
1116
1125
  },
1117
1126
  name: "text"
1118
1127
  };
1119
-
1120
1128
  //#endregion
1121
1129
  //#region src/parsers/yaml.ts
1122
1130
  const yamlParser = {
@@ -1129,14 +1137,13 @@ const yamlParser = {
1129
1137
  const data = Buffer.isBuffer(file.data) ? file.data.toString() : file.data;
1130
1138
  if (typeof data !== "string") return data;
1131
1139
  try {
1132
- return yaml.load(data, { schema: JSON_SCHEMA });
1140
+ return parse(data);
1133
1141
  } catch (error) {
1134
1142
  throw new ParserError(error?.message || "Parser Error", file.url);
1135
1143
  }
1136
1144
  },
1137
1145
  name: "yaml"
1138
1146
  };
1139
-
1140
1147
  //#endregion
1141
1148
  //#region src/options.ts
1142
1149
  const getJsonSchemaRefParserDefaultOptions = () => ({
@@ -1152,7 +1159,6 @@ const getJsonSchemaRefParserDefaultOptions = () => ({
1152
1159
  yaml: { ...yamlParser }
1153
1160
  }
1154
1161
  });
1155
-
1156
1162
  //#endregion
1157
1163
  //#region src/util/plugins.ts
1158
1164
  /**
@@ -1167,13 +1173,13 @@ async function run(plugins, file) {
1167
1173
  let index = 0;
1168
1174
  let lastError;
1169
1175
  let plugin;
1170
- return new Promise((resolve$1, reject) => {
1176
+ return new Promise((resolve, reject) => {
1171
1177
  const runNextPlugin = async () => {
1172
1178
  plugin = plugins[index++];
1173
1179
  if (!plugin) return reject(lastError);
1174
1180
  try {
1175
1181
  const result = await plugin.handler(file);
1176
- if (result !== void 0) return resolve$1({
1182
+ if (result !== void 0) return resolve({
1177
1183
  plugin,
1178
1184
  result
1179
1185
  });
@@ -1189,7 +1195,6 @@ async function run(plugins, file) {
1189
1195
  runNextPlugin();
1190
1196
  });
1191
1197
  }
1192
-
1193
1198
  //#endregion
1194
1199
  //#region src/parse.ts
1195
1200
  /**
@@ -1231,7 +1236,6 @@ async function parseFile(file, options) {
1231
1236
  throw new ParserError(error.error.message, file.url);
1232
1237
  }
1233
1238
  }
1234
-
1235
1239
  //#endregion
1236
1240
  //#region src/refs.ts
1237
1241
  /**
@@ -1336,7 +1340,7 @@ var $Refs = class {
1336
1340
  */
1337
1341
  _add(path) {
1338
1342
  const withoutHash = stripHash(path);
1339
- const $ref = new ref_default(this);
1343
+ const $ref = new $Ref(this);
1340
1344
  $ref.path = withoutHash;
1341
1345
  this._$refs[withoutHash] = $ref;
1342
1346
  this._root$Ref = this._root$Ref || $ref;
@@ -1416,13 +1420,12 @@ var $Refs = class {
1416
1420
  function getPaths($refs, types) {
1417
1421
  let paths = Object.keys($refs);
1418
1422
  types = Array.isArray(types[0]) ? types[0] : Array.prototype.slice.call(types);
1419
- if (types.length > 0 && types[0]) paths = paths.filter((key) => types.includes($refs[key].pathType));
1423
+ if (types.length && types[0]) paths = paths.filter((key) => types.includes($refs[key].pathType));
1420
1424
  return paths.map((path) => ({
1421
1425
  decoded: $refs[path].pathType === "file" ? toFileSystemPath(path, true) : path,
1422
1426
  encoded: path
1423
1427
  }));
1424
1428
  }
1425
-
1426
1429
  //#endregion
1427
1430
  //#region src/resolvers/file.ts
1428
1431
  const fileResolver = { handler: async ({ file }) => {
@@ -1438,7 +1441,6 @@ const fileResolver = { handler: async ({ file }) => {
1438
1441
  throw new ResolverError(ono(error, `Error opening file "${path}"`), path);
1439
1442
  }
1440
1443
  } };
1441
-
1442
1444
  //#endregion
1443
1445
  //#region src/resolvers/url.ts
1444
1446
  const sendRequest = async ({ fetchOptions, redirects = [], timeout = 6e4, url }) => {
@@ -1487,7 +1489,6 @@ const urlResolver = { handler: async ({ arrayBuffer, fetch: _fetch, file }) => {
1487
1489
  }
1488
1490
  file.data = Buffer.from(data);
1489
1491
  } };
1490
-
1491
1492
  //#endregion
1492
1493
  //#region src/resolve-external.ts
1493
1494
  /**
@@ -1521,7 +1522,7 @@ function crawl(obj, { $refs, external = false, options, path, seen = /* @__PURE_
1521
1522
  let promises = [];
1522
1523
  if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) {
1523
1524
  seen.add(obj);
1524
- if (ref_default.isExternal$Ref(obj)) promises.push(resolve$Ref(obj, {
1525
+ if ($Ref.isExternal$Ref(obj)) promises.push(resolve$Ref(obj, {
1525
1526
  $refs,
1526
1527
  options,
1527
1528
  path,
@@ -1531,7 +1532,7 @@ function crawl(obj, { $refs, external = false, options, path, seen = /* @__PURE_
1531
1532
  $refs,
1532
1533
  external,
1533
1534
  options,
1534
- path: pointer_default.join(path, key),
1535
+ path: Pointer.join(path, key),
1535
1536
  seen
1536
1537
  }));
1537
1538
  }
@@ -1587,7 +1588,6 @@ async function resolve$Ref($ref, { $refs, options, path, seen }) {
1587
1588
  throw error;
1588
1589
  }
1589
1590
  }
1590
-
1591
1591
  //#endregion
1592
1592
  //#region src/index.ts
1593
1593
  function getResolvedInput({ pathOrUrlOrSchema }) {
@@ -1643,35 +1643,35 @@ var $RefParser = class {
1643
1643
  *
1644
1644
  * @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
1645
1645
  */
1646
- async bundle({ arrayBuffer, fetch: fetch$1, pathOrUrlOrSchema, resolvedInput }) {
1646
+ async bundle({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput }) {
1647
1647
  await this.parse({
1648
1648
  arrayBuffer,
1649
- fetch: fetch$1,
1649
+ fetch,
1650
1650
  pathOrUrlOrSchema,
1651
1651
  resolvedInput
1652
1652
  });
1653
1653
  await resolveExternal(this, this.options);
1654
- if (JSONParserErrorGroup.getParserErrors(this).length > 0) throw new JSONParserErrorGroup(this);
1654
+ if (JSONParserErrorGroup.getParserErrors(this).length) throw new JSONParserErrorGroup(this);
1655
1655
  bundle(this, this.options);
1656
- if (JSONParserErrorGroup.getParserErrors(this).length > 0) throw new JSONParserErrorGroup(this);
1656
+ if (JSONParserErrorGroup.getParserErrors(this).length) throw new JSONParserErrorGroup(this);
1657
1657
  return this.schema;
1658
1658
  }
1659
1659
  /**
1660
1660
  * Bundles multiple roots (files/URLs/objects) into a single schema by creating a synthetic root
1661
1661
  * that references each input, resolving all externals, and then hoisting via the existing bundler.
1662
1662
  */
1663
- async bundleMany({ arrayBuffer, fetch: fetch$1, pathOrUrlOrSchemas, resolvedInputs }) {
1663
+ async bundleMany({ arrayBuffer, fetch, pathOrUrlOrSchemas, resolvedInputs }) {
1664
1664
  await this.parseMany({
1665
1665
  arrayBuffer,
1666
- fetch: fetch$1,
1666
+ fetch,
1667
1667
  pathOrUrlOrSchemas,
1668
1668
  resolvedInputs
1669
1669
  });
1670
1670
  this.mergeMany();
1671
1671
  await resolveExternal(this, this.options);
1672
- if (JSONParserErrorGroup.getParserErrors(this).length > 0) throw new JSONParserErrorGroup(this);
1672
+ if (JSONParserErrorGroup.getParserErrors(this).length) throw new JSONParserErrorGroup(this);
1673
1673
  bundle(this, this.options);
1674
- if (JSONParserErrorGroup.getParserErrors(this).length > 0) throw new JSONParserErrorGroup(this);
1674
+ if (JSONParserErrorGroup.getParserErrors(this).length) throw new JSONParserErrorGroup(this);
1675
1675
  return this.schema;
1676
1676
  }
1677
1677
  /**
@@ -1682,7 +1682,7 @@ var $RefParser = class {
1682
1682
  * @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
1683
1683
  * @returns - The returned promise resolves with the parsed JSON schema object.
1684
1684
  */
1685
- async parse({ arrayBuffer, fetch: fetch$1, pathOrUrlOrSchema, resolvedInput: _resolvedInput }) {
1685
+ async parse({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput: _resolvedInput }) {
1686
1686
  const resolvedInput = _resolvedInput || getResolvedInput({ pathOrUrlOrSchema });
1687
1687
  const { path, type } = resolvedInput;
1688
1688
  let { schema } = resolvedInput;
@@ -1699,7 +1699,7 @@ var $RefParser = class {
1699
1699
  try {
1700
1700
  await (type === "file" ? fileResolver : urlResolver).handler({
1701
1701
  arrayBuffer,
1702
- fetch: fetch$1,
1702
+ fetch,
1703
1703
  file
1704
1704
  });
1705
1705
  const parseResult = await parseFile(file, this.options.parse);
@@ -1714,7 +1714,7 @@ var $RefParser = class {
1714
1714
  this.schema = schema;
1715
1715
  return { schema };
1716
1716
  }
1717
- async parseMany({ arrayBuffer, fetch: fetch$1, pathOrUrlOrSchemas, resolvedInputs: _resolvedInputs }) {
1717
+ async parseMany({ arrayBuffer, fetch, pathOrUrlOrSchemas, resolvedInputs: _resolvedInputs }) {
1718
1718
  const resolvedInputs = [..._resolvedInputs || []];
1719
1719
  resolvedInputs.push(...pathOrUrlOrSchemas.map((schema) => getResolvedInput({ pathOrUrlOrSchema: schema })) || []);
1720
1720
  this.schemaMany = [];
@@ -1731,7 +1731,7 @@ var $RefParser = class {
1731
1731
  try {
1732
1732
  await (type === "file" ? fileResolver : urlResolver).handler({
1733
1733
  arrayBuffer: arrayBuffer?.[i],
1734
- fetch: fetch$1,
1734
+ fetch,
1735
1735
  file
1736
1736
  });
1737
1737
  const parseResult = await parseFile(file, this.options.parse);
@@ -1750,7 +1750,7 @@ var $RefParser = class {
1750
1750
  }
1751
1751
  mergeMany() {
1752
1752
  const schemas = this.schemaMany || [];
1753
- if (schemas.length === 0) throw ono("mergeMany called with no schemas. Did you run parseMany?");
1753
+ if (!schemas.length) throw ono("mergeMany called with no schemas. Did you run parseMany?");
1754
1754
  const merged = {};
1755
1755
  let chosenOpenapi;
1756
1756
  let chosenSwagger;
@@ -1768,7 +1768,7 @@ var $RefParser = class {
1768
1768
  for (const [k, v] of Object.entries(info)) if (infoAccumulator[k] === void 0 && v !== void 0) infoAccumulator[k] = JSON.parse(JSON.stringify(v));
1769
1769
  }
1770
1770
  }
1771
- if (Object.keys(infoAccumulator).length > 0) merged.info = infoAccumulator;
1771
+ if (Object.keys(infoAccumulator).length) merged.info = infoAccumulator;
1772
1772
  const servers = [];
1773
1773
  const seenServers = /* @__PURE__ */ new Set();
1774
1774
  for (const s of schemas) {
@@ -1783,7 +1783,7 @@ var $RefParser = class {
1783
1783
  }
1784
1784
  }
1785
1785
  }
1786
- if (servers.length > 0) merged.servers = servers;
1786
+ if (servers.length) merged.servers = servers;
1787
1787
  merged.paths = {};
1788
1788
  merged.components = {};
1789
1789
  const componentSections = [
@@ -1904,7 +1904,7 @@ var $RefParser = class {
1904
1904
  } else Object.assign(merged.paths[p], rewritten);
1905
1905
  } else merged.paths[p] = cloneAndRewrite(item, refMap, tagMap, prefix, stripHash(sourcePath));
1906
1906
  }
1907
- if (tags.length > 0) merged.tags = tags;
1907
+ if (tags.length) merged.tags = tags;
1908
1908
  const rootPath = this.schemaManySources[0] || cwd();
1909
1909
  this.$refs = new $Refs();
1910
1910
  const rootRef = this.$refs._add(rootPath);
@@ -1914,7 +1914,7 @@ var $RefParser = class {
1914
1914
  return merged;
1915
1915
  }
1916
1916
  };
1917
-
1918
1917
  //#endregion
1919
- export { $RefParser, getResolvedInput, sendRequest };
1918
+ export { $RefParser, InvalidPointerError, JSONParserError, JSONParserErrorGroup, MissingPointerError, ParserError, ResolverError, TimeoutError, UnmatchedParserError, UnmatchedResolverError, getResolvedInput, isHandledError, normalizeError, sendRequest };
1919
+
1920
1920
  //# sourceMappingURL=index.mjs.map