@rjsf/utils 5.18.1 → 5.18.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/LICENSE.md CHANGED
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright 2015-2024 rjsf-team
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -284,20 +284,30 @@ function splitKeyElementFromObject(key, object) {
284
284
  const remaining = (0, import_omit.default)(object, [key]);
285
285
  return [remaining, value];
286
286
  }
287
- function findSchemaDefinition($ref, rootSchema = {}) {
288
- let ref = $ref || "";
287
+ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
288
+ const ref = $ref || "";
289
+ let decodedRef;
289
290
  if (ref.startsWith("#")) {
290
- ref = decodeURIComponent(ref.substring(1));
291
+ decodedRef = decodeURIComponent(ref.substring(1));
291
292
  } else {
292
293
  throw new Error(`Could not find a definition for ${$ref}.`);
293
294
  }
294
- const current = import_jsonpointer.default.get(rootSchema, ref);
295
+ const current = import_jsonpointer.default.get(rootSchema, decodedRef);
295
296
  if (current === void 0) {
296
297
  throw new Error(`Could not find a definition for ${$ref}.`);
297
298
  }
298
- if (current[REF_KEY]) {
299
+ const nextRef = current[REF_KEY];
300
+ if (nextRef) {
301
+ if (recurseList.includes(nextRef)) {
302
+ if (recurseList.length === 1) {
303
+ throw new Error(`Definition for ${$ref} is a circular reference`);
304
+ }
305
+ const [firstRef, ...restRefs] = recurseList;
306
+ const circularPath = [...restRefs, ref, firstRef].join(" -> ");
307
+ throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
308
+ }
299
309
  const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
300
- const subSchema = findSchemaDefinition(theRef, rootSchema);
310
+ const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
301
311
  if (Object.keys(remaining).length > 0) {
302
312
  return { ...remaining, ...subSchema };
303
313
  }
@@ -305,6 +315,10 @@ function findSchemaDefinition($ref, rootSchema = {}) {
305
315
  }
306
316
  return current;
307
317
  }
318
+ function findSchemaDefinition($ref, rootSchema = {}) {
319
+ const recurseList = [];
320
+ return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
321
+ }
308
322
 
309
323
  // src/schema/getClosestMatchingOption.ts
310
324
  var import_get5 = __toESM(require("lodash/get"));