@rjsf/utils 5.18.0 → 5.18.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/dist/index.js +20 -6
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +20 -6
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +20 -6
- package/lib/findSchemaDefinition.d.ts +16 -3
- package/lib/findSchemaDefinition.js +37 -10
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/findSchemaDefinition.ts +43 -11
package/dist/utils.esm.js
CHANGED
|
@@ -149,20 +149,30 @@ function splitKeyElementFromObject(key, object) {
|
|
|
149
149
|
const remaining = omit(object, [key]);
|
|
150
150
|
return [remaining, value];
|
|
151
151
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
152
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
153
|
+
const ref = $ref || "";
|
|
154
|
+
let decodedRef;
|
|
154
155
|
if (ref.startsWith("#")) {
|
|
155
|
-
|
|
156
|
+
decodedRef = decodeURIComponent(ref.substring(1));
|
|
156
157
|
} else {
|
|
157
158
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
158
159
|
}
|
|
159
|
-
const current = jsonpointer.get(rootSchema,
|
|
160
|
+
const current = jsonpointer.get(rootSchema, decodedRef);
|
|
160
161
|
if (current === void 0) {
|
|
161
162
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
+
const nextRef = current[REF_KEY];
|
|
165
|
+
if (nextRef) {
|
|
166
|
+
if (recurseList.includes(nextRef)) {
|
|
167
|
+
if (recurseList.length === 1) {
|
|
168
|
+
throw new Error(`Definition for ${$ref} is a circular reference`);
|
|
169
|
+
}
|
|
170
|
+
const [firstRef, ...restRefs] = recurseList;
|
|
171
|
+
const circularPath = [...restRefs, ref, firstRef].join(" -> ");
|
|
172
|
+
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
173
|
+
}
|
|
164
174
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
165
|
-
const subSchema =
|
|
175
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
166
176
|
if (Object.keys(remaining).length > 0) {
|
|
167
177
|
return { ...remaining, ...subSchema };
|
|
168
178
|
}
|
|
@@ -170,6 +180,10 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
170
180
|
}
|
|
171
181
|
return current;
|
|
172
182
|
}
|
|
183
|
+
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
184
|
+
const recurseList = [];
|
|
185
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
186
|
+
}
|
|
173
187
|
|
|
174
188
|
// src/schema/getClosestMatchingOption.ts
|
|
175
189
|
import get5 from "lodash/get";
|