@rjsf/utils 5.13.0 → 5.13.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.js +243 -125
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +243 -125
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +223 -111
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +12 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js +36 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -0
- package/lib/getSchemaType.js +7 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/parser/schemaParser.js +3 -2
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +7 -1
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +9 -12
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getMatchingOption.js +6 -0
- package/lib/schema/getMatchingOption.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +16 -14
- package/lib/schema/retrieveSchema.js +57 -43
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +15 -15
- package/src/getOptionMatchingSimpleDiscriminator.ts +46 -0
- package/src/getSchemaType.ts +6 -2
- package/src/index.ts +2 -0
- package/src/parser/schemaParser.ts +3 -2
- package/src/schema/getClosestMatchingOption.ts +9 -1
- package/src/schema/getDefaultFormState.ts +9 -12
- package/src/schema/getMatchingOption.ts +8 -0
- package/src/schema/retrieveSchema.ts +145 -39
- package/src/types.ts +1 -1
package/dist/utils.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/isEmpty'), require('jsonpointer'), require('lodash/omit'), require('lodash/has'), require('lodash/isObject'), require('lodash/isString'), require('lodash/reduce'), require('lodash/times'), require('lodash/set'), require('lodash/transform'), require('json-schema-merge-allof'), require('lodash/union'), require('lodash
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/isEmpty', 'jsonpointer', 'lodash/omit', 'lodash/has', 'lodash/isObject', 'lodash/isString', 'lodash/reduce', 'lodash/times', 'lodash/set', 'lodash/transform', 'json-schema-merge-allof', 'lodash/union', 'lodash
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject, global.isEqualWith, global.
|
|
5
|
-
})(this, (function (exports, isPlainObject, isEqualWith,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/isEmpty'), require('jsonpointer'), require('lodash/omit'), require('lodash/has'), require('lodash/isNumber'), require('lodash/isObject'), require('lodash/isString'), require('lodash/reduce'), require('lodash/times'), require('lodash/isEqual'), require('lodash/set'), require('lodash/transform'), require('json-schema-merge-allof'), require('lodash/union'), require('lodash'), require('lodash/cloneDeep'), require('react'), require('react-is'), require('react/jsx-runtime'), require('lodash/toPath'), require('lodash/forEach')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/isEmpty', 'jsonpointer', 'lodash/omit', 'lodash/has', 'lodash/isNumber', 'lodash/isObject', 'lodash/isString', 'lodash/reduce', 'lodash/times', 'lodash/isEqual', 'lodash/set', 'lodash/transform', 'json-schema-merge-allof', 'lodash/union', 'lodash', 'lodash/cloneDeep', 'react', 'react-is', 'react/jsx-runtime', 'lodash/toPath', 'lodash/forEach'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject, global.isEqualWith, global.get8, global.isEmpty, global.jsonpointer, global.omit, global.has3, global.isNumber, global.isObject2, global.isString, global.reduce, global.times, global.isEqual4, global.set3, global.transform, global.mergeAllOf, global.union, global.lodash, global.cloneDeep, global.react, global.ReactIs, global.jsxRuntime, global.toPath, global.forEach));
|
|
5
|
+
})(this, (function (exports, isPlainObject, isEqualWith, get8, isEmpty, jsonpointer, omit, has3, isNumber, isObject2, isString, reduce, times, isEqual4, set3, transform, mergeAllOf, union, lodash, cloneDeep, react, ReactIs, jsxRuntime, toPath, forEach) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/isObject.ts
|
|
8
8
|
function isObject(thing) {
|
|
@@ -162,15 +162,43 @@
|
|
|
162
162
|
}
|
|
163
163
|
return current;
|
|
164
164
|
}
|
|
165
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
166
|
+
if (formData && discriminatorField) {
|
|
167
|
+
const value = get8(formData, discriminatorField);
|
|
168
|
+
if (value === void 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < options.length; i++) {
|
|
172
|
+
const option = options[i];
|
|
173
|
+
const discriminator = get8(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
174
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (discriminator.const === value) {
|
|
178
|
+
return i;
|
|
179
|
+
}
|
|
180
|
+
if (discriminator.enum?.includes(value)) {
|
|
181
|
+
return i;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/schema/getMatchingOption.ts
|
|
165
189
|
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
166
190
|
if (formData === void 0) {
|
|
167
191
|
return 0;
|
|
168
192
|
}
|
|
193
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
194
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
195
|
+
return simpleDiscriminatorMatch;
|
|
196
|
+
}
|
|
169
197
|
for (let i = 0; i < options.length; i++) {
|
|
170
198
|
const option = options[i];
|
|
171
199
|
if (discriminatorField && has3(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
172
|
-
const value =
|
|
173
|
-
const discriminator =
|
|
200
|
+
const value = get8(formData, discriminatorField);
|
|
201
|
+
const discriminator = get8(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
174
202
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
175
203
|
return i;
|
|
176
204
|
}
|
|
@@ -210,7 +238,7 @@
|
|
|
210
238
|
}
|
|
211
239
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
212
240
|
let discriminator;
|
|
213
|
-
const maybeString =
|
|
241
|
+
const maybeString = get8(schema, "discriminator.propertyName", void 0);
|
|
214
242
|
if (isString(maybeString)) {
|
|
215
243
|
discriminator = maybeString;
|
|
216
244
|
} else if (maybeString !== void 0) {
|
|
@@ -254,8 +282,12 @@
|
|
|
254
282
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
255
283
|
return "object";
|
|
256
284
|
}
|
|
257
|
-
if (Array.isArray(type)
|
|
258
|
-
|
|
285
|
+
if (Array.isArray(type)) {
|
|
286
|
+
if (type.length === 2 && type.includes("null")) {
|
|
287
|
+
type = type.find((type2) => type2 !== "null");
|
|
288
|
+
} else {
|
|
289
|
+
type = type[0];
|
|
290
|
+
}
|
|
259
291
|
}
|
|
260
292
|
return type;
|
|
261
293
|
}
|
|
@@ -280,7 +312,7 @@
|
|
|
280
312
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
281
313
|
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
282
314
|
}
|
|
283
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
315
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
284
316
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
285
317
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
286
318
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -288,19 +320,26 @@
|
|
|
288
320
|
if (expandAllBranches) {
|
|
289
321
|
if (then && typeof then !== "boolean") {
|
|
290
322
|
schemas = schemas.concat(
|
|
291
|
-
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
|
|
323
|
+
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList)
|
|
292
324
|
);
|
|
293
325
|
}
|
|
294
326
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
295
327
|
schemas = schemas.concat(
|
|
296
|
-
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
|
|
328
|
+
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList)
|
|
297
329
|
);
|
|
298
330
|
}
|
|
299
331
|
} else {
|
|
300
332
|
const conditionalSchema = conditionValue ? then : otherwise;
|
|
301
333
|
if (conditionalSchema && typeof conditionalSchema !== "boolean") {
|
|
302
334
|
schemas = schemas.concat(
|
|
303
|
-
retrieveSchemaInternal(
|
|
335
|
+
retrieveSchemaInternal(
|
|
336
|
+
validator,
|
|
337
|
+
conditionalSchema,
|
|
338
|
+
rootSchema,
|
|
339
|
+
formData,
|
|
340
|
+
expandAllBranches,
|
|
341
|
+
recurseList
|
|
342
|
+
)
|
|
304
343
|
);
|
|
305
344
|
}
|
|
306
345
|
}
|
|
@@ -308,7 +347,7 @@
|
|
|
308
347
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
309
348
|
}
|
|
310
349
|
return resolvedSchemas.flatMap(
|
|
311
|
-
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
|
|
350
|
+
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList)
|
|
312
351
|
);
|
|
313
352
|
}
|
|
314
353
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -325,40 +364,72 @@
|
|
|
325
364
|
);
|
|
326
365
|
return allPermutations;
|
|
327
366
|
}
|
|
328
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
329
|
-
|
|
330
|
-
|
|
367
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
368
|
+
const updatedSchemas = resolveReference(
|
|
369
|
+
validator,
|
|
370
|
+
schema,
|
|
371
|
+
rootSchema,
|
|
372
|
+
expandAllBranches,
|
|
373
|
+
recurseList,
|
|
374
|
+
formData
|
|
375
|
+
);
|
|
376
|
+
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
377
|
+
return updatedSchemas;
|
|
331
378
|
}
|
|
332
379
|
if (DEPENDENCIES_KEY in schema) {
|
|
333
|
-
const resolvedSchemas = resolveDependencies(
|
|
380
|
+
const resolvedSchemas = resolveDependencies(
|
|
381
|
+
validator,
|
|
382
|
+
schema,
|
|
383
|
+
rootSchema,
|
|
384
|
+
expandAllBranches,
|
|
385
|
+
recurseList,
|
|
386
|
+
formData
|
|
387
|
+
);
|
|
334
388
|
return resolvedSchemas.flatMap((s) => {
|
|
335
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
389
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList);
|
|
336
390
|
});
|
|
337
391
|
}
|
|
338
392
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
339
393
|
const allOfSchemaElements = schema.allOf.map(
|
|
340
|
-
(allOfSubschema) => retrieveSchemaInternal(
|
|
394
|
+
(allOfSubschema) => retrieveSchemaInternal(
|
|
395
|
+
validator,
|
|
396
|
+
allOfSubschema,
|
|
397
|
+
rootSchema,
|
|
398
|
+
formData,
|
|
399
|
+
expandAllBranches,
|
|
400
|
+
recurseList
|
|
401
|
+
)
|
|
341
402
|
);
|
|
342
403
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
343
404
|
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
344
405
|
}
|
|
345
406
|
return [schema];
|
|
346
407
|
}
|
|
347
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
408
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
409
|
+
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
410
|
+
if (updatedSchema !== schema) {
|
|
411
|
+
return retrieveSchemaInternal(
|
|
412
|
+
validator,
|
|
413
|
+
updatedSchema,
|
|
414
|
+
rootSchema,
|
|
415
|
+
formData,
|
|
416
|
+
expandAllBranches,
|
|
417
|
+
recurseList
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
return [schema];
|
|
357
421
|
}
|
|
358
|
-
function resolveAllReferences(schema, rootSchema) {
|
|
422
|
+
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
423
|
+
if (!isObject(schema)) {
|
|
424
|
+
return schema;
|
|
425
|
+
}
|
|
359
426
|
let resolvedSchema = schema;
|
|
360
427
|
if (REF_KEY in resolvedSchema) {
|
|
361
428
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
429
|
+
if (recurseList.includes($ref)) {
|
|
430
|
+
return resolvedSchema;
|
|
431
|
+
}
|
|
432
|
+
recurseList.push($ref);
|
|
362
433
|
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
363
434
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
364
435
|
}
|
|
@@ -366,16 +437,19 @@
|
|
|
366
437
|
const updatedProps = transform(
|
|
367
438
|
resolvedSchema[PROPERTIES_KEY],
|
|
368
439
|
(result, value, key) => {
|
|
369
|
-
result[key] = resolveAllReferences(value, rootSchema);
|
|
440
|
+
result[key] = resolveAllReferences(value, rootSchema, recurseList);
|
|
370
441
|
},
|
|
371
442
|
{}
|
|
372
443
|
);
|
|
373
444
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
374
445
|
}
|
|
375
446
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
376
|
-
resolvedSchema = {
|
|
447
|
+
resolvedSchema = {
|
|
448
|
+
...resolvedSchema,
|
|
449
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
450
|
+
};
|
|
377
451
|
}
|
|
378
|
-
return resolvedSchema;
|
|
452
|
+
return isEqual4(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
379
453
|
}
|
|
380
454
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
381
455
|
const schema = {
|
|
@@ -392,7 +466,7 @@
|
|
|
392
466
|
if (REF_KEY in schema.additionalProperties) {
|
|
393
467
|
additionalProperties = retrieveSchema(
|
|
394
468
|
validator,
|
|
395
|
-
{ $ref:
|
|
469
|
+
{ $ref: get8(schema.additionalProperties, [REF_KEY]) },
|
|
396
470
|
rootSchema,
|
|
397
471
|
formData
|
|
398
472
|
);
|
|
@@ -404,25 +478,39 @@
|
|
|
404
478
|
...schema.additionalProperties
|
|
405
479
|
};
|
|
406
480
|
} else {
|
|
407
|
-
additionalProperties = { type: guessType(
|
|
481
|
+
additionalProperties = { type: guessType(get8(formData, [key])) };
|
|
408
482
|
}
|
|
409
483
|
} else {
|
|
410
|
-
additionalProperties = { type: guessType(
|
|
484
|
+
additionalProperties = { type: guessType(get8(formData, [key])) };
|
|
411
485
|
}
|
|
412
486
|
schema.properties[key] = additionalProperties;
|
|
413
487
|
set3(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
414
488
|
});
|
|
415
489
|
return schema;
|
|
416
490
|
}
|
|
417
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
491
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
418
492
|
if (!isObject(schema)) {
|
|
419
493
|
return [{}];
|
|
420
494
|
}
|
|
421
|
-
const resolvedSchemas = resolveSchema(
|
|
495
|
+
const resolvedSchemas = resolveSchema(
|
|
496
|
+
validator,
|
|
497
|
+
schema,
|
|
498
|
+
rootSchema,
|
|
499
|
+
expandAllBranches,
|
|
500
|
+
recurseList,
|
|
501
|
+
rawFormData
|
|
502
|
+
);
|
|
422
503
|
return resolvedSchemas.flatMap((s) => {
|
|
423
504
|
let resolvedSchema = s;
|
|
424
505
|
if (IF_KEY in resolvedSchema) {
|
|
425
|
-
return resolveCondition(
|
|
506
|
+
return resolveCondition(
|
|
507
|
+
validator,
|
|
508
|
+
resolvedSchema,
|
|
509
|
+
rootSchema,
|
|
510
|
+
expandAllBranches,
|
|
511
|
+
recurseList,
|
|
512
|
+
rawFormData
|
|
513
|
+
);
|
|
426
514
|
}
|
|
427
515
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
428
516
|
if (expandAllBranches) {
|
|
@@ -446,7 +534,7 @@
|
|
|
446
534
|
return resolvedSchema;
|
|
447
535
|
});
|
|
448
536
|
}
|
|
449
|
-
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
537
|
+
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData) {
|
|
450
538
|
let anyOrOneOf;
|
|
451
539
|
const { oneOf, anyOf, ...remaining } = schema;
|
|
452
540
|
if (Array.isArray(oneOf)) {
|
|
@@ -458,7 +546,7 @@
|
|
|
458
546
|
const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
|
|
459
547
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
460
548
|
anyOrOneOf = anyOrOneOf.map((s) => {
|
|
461
|
-
return resolveAllReferences(s, rootSchema);
|
|
549
|
+
return resolveAllReferences(s, rootSchema, recurseList);
|
|
462
550
|
});
|
|
463
551
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
464
552
|
if (expandAllBranches) {
|
|
@@ -468,23 +556,32 @@
|
|
|
468
556
|
}
|
|
469
557
|
return [schema];
|
|
470
558
|
}
|
|
471
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
559
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
472
560
|
const { dependencies, ...remainingSchema } = schema;
|
|
473
561
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
474
562
|
validator,
|
|
475
563
|
remainingSchema,
|
|
476
564
|
rootSchema,
|
|
477
565
|
expandAllBranches,
|
|
566
|
+
recurseList,
|
|
478
567
|
formData
|
|
479
568
|
);
|
|
480
569
|
return resolvedSchemas.flatMap(
|
|
481
|
-
(resolvedSchema) => processDependencies(
|
|
570
|
+
(resolvedSchema) => processDependencies(
|
|
571
|
+
validator,
|
|
572
|
+
dependencies,
|
|
573
|
+
resolvedSchema,
|
|
574
|
+
rootSchema,
|
|
575
|
+
expandAllBranches,
|
|
576
|
+
recurseList,
|
|
577
|
+
formData
|
|
578
|
+
)
|
|
482
579
|
);
|
|
483
580
|
}
|
|
484
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
581
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
485
582
|
let schemas = [resolvedSchema];
|
|
486
583
|
for (const dependencyKey in dependencies) {
|
|
487
|
-
if (!expandAllBranches &&
|
|
584
|
+
if (!expandAllBranches && get8(formData, [dependencyKey]) === void 0) {
|
|
488
585
|
continue;
|
|
489
586
|
}
|
|
490
587
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -504,11 +601,20 @@
|
|
|
504
601
|
dependencyKey,
|
|
505
602
|
dependencyValue,
|
|
506
603
|
expandAllBranches,
|
|
604
|
+
recurseList,
|
|
507
605
|
formData
|
|
508
606
|
);
|
|
509
607
|
}
|
|
510
608
|
return schemas.flatMap(
|
|
511
|
-
(schema) => processDependencies(
|
|
609
|
+
(schema) => processDependencies(
|
|
610
|
+
validator,
|
|
611
|
+
remainingDependencies,
|
|
612
|
+
schema,
|
|
613
|
+
rootSchema,
|
|
614
|
+
expandAllBranches,
|
|
615
|
+
recurseList,
|
|
616
|
+
formData
|
|
617
|
+
)
|
|
512
618
|
);
|
|
513
619
|
}
|
|
514
620
|
return schemas;
|
|
@@ -520,13 +626,14 @@
|
|
|
520
626
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
521
627
|
return { ...schema, required };
|
|
522
628
|
}
|
|
523
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
629
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
524
630
|
const dependentSchemas = retrieveSchemaInternal(
|
|
525
631
|
validator,
|
|
526
632
|
dependencyValue,
|
|
527
633
|
rootSchema,
|
|
528
634
|
formData,
|
|
529
|
-
expandAllBranches
|
|
635
|
+
expandAllBranches,
|
|
636
|
+
recurseList
|
|
530
637
|
);
|
|
531
638
|
return dependentSchemas.flatMap((dependent) => {
|
|
532
639
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -538,7 +645,7 @@
|
|
|
538
645
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
539
646
|
return [subschema];
|
|
540
647
|
}
|
|
541
|
-
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
648
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
542
649
|
});
|
|
543
650
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
544
651
|
return allPermutations.flatMap(
|
|
@@ -549,12 +656,13 @@
|
|
|
549
656
|
dependencyKey,
|
|
550
657
|
resolvedOneOf,
|
|
551
658
|
expandAllBranches,
|
|
659
|
+
recurseList,
|
|
552
660
|
formData
|
|
553
661
|
)
|
|
554
662
|
);
|
|
555
663
|
});
|
|
556
664
|
}
|
|
557
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
665
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
558
666
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
559
667
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
560
668
|
return false;
|
|
@@ -584,7 +692,8 @@
|
|
|
584
692
|
dependentSchema,
|
|
585
693
|
rootSchema,
|
|
586
694
|
formData,
|
|
587
|
-
expandAllBranches
|
|
695
|
+
expandAllBranches,
|
|
696
|
+
recurseList
|
|
588
697
|
);
|
|
589
698
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
590
699
|
});
|
|
@@ -607,7 +716,7 @@
|
|
|
607
716
|
totalScore += reduce(
|
|
608
717
|
schema.properties,
|
|
609
718
|
(score, value, key) => {
|
|
610
|
-
const formValue =
|
|
719
|
+
const formValue = get8(formData, key);
|
|
611
720
|
if (typeof value === "boolean") {
|
|
612
721
|
return score;
|
|
613
722
|
}
|
|
@@ -622,7 +731,7 @@
|
|
|
622
731
|
validator,
|
|
623
732
|
rootSchema,
|
|
624
733
|
formValue,
|
|
625
|
-
|
|
734
|
+
get8(value, key2),
|
|
626
735
|
-1,
|
|
627
736
|
discriminator
|
|
628
737
|
);
|
|
@@ -651,8 +760,12 @@
|
|
|
651
760
|
}
|
|
652
761
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
653
762
|
const resolvedOptions = options.map((option) => {
|
|
654
|
-
return resolveAllReferences(option, rootSchema);
|
|
763
|
+
return resolveAllReferences(option, rootSchema, []);
|
|
655
764
|
});
|
|
765
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
766
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
767
|
+
return simpleDiscriminatorMatch;
|
|
768
|
+
}
|
|
656
769
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
657
770
|
const testOptions = [JUNK_OPTION, option];
|
|
658
771
|
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
@@ -709,8 +822,8 @@
|
|
|
709
822
|
const acc = Object.assign({}, defaults);
|
|
710
823
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
711
824
|
acc2[key] = mergeDefaultsWithFormData(
|
|
712
|
-
defaults ?
|
|
713
|
-
|
|
825
|
+
defaults ? get8(defaults, key) : {},
|
|
826
|
+
get8(formData, key),
|
|
714
827
|
mergeExtraArrayDefaults
|
|
715
828
|
);
|
|
716
829
|
return acc2;
|
|
@@ -831,7 +944,7 @@
|
|
|
831
944
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
832
945
|
}
|
|
833
946
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
834
|
-
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
947
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData);
|
|
835
948
|
schemaToCompute = resolvedSchema[0];
|
|
836
949
|
} else if (isFixedItems(schema)) {
|
|
837
950
|
defaults = schema.items.map(
|
|
@@ -893,13 +1006,13 @@
|
|
|
893
1006
|
switch (getSchemaType(schema)) {
|
|
894
1007
|
case "object": {
|
|
895
1008
|
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
896
|
-
const computedDefault = computeDefaults(validator,
|
|
1009
|
+
const computedDefault = computeDefaults(validator, get8(schema, [PROPERTIES_KEY, key]), {
|
|
897
1010
|
rootSchema,
|
|
898
1011
|
_recurseList,
|
|
899
1012
|
experimental_defaultFormStateBehavior,
|
|
900
1013
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
901
|
-
parentDefaults:
|
|
902
|
-
rawFormData:
|
|
1014
|
+
parentDefaults: get8(defaults, [key]),
|
|
1015
|
+
rawFormData: get8(formData, [key]),
|
|
903
1016
|
required: schema.required?.includes(key)
|
|
904
1017
|
});
|
|
905
1018
|
maybeAddDefaultToObject(
|
|
@@ -919,22 +1032,19 @@
|
|
|
919
1032
|
if (isObject(defaults)) {
|
|
920
1033
|
Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
|
|
921
1034
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
formDataRequired.push(key);
|
|
928
|
-
});
|
|
929
|
-
}
|
|
1035
|
+
const formDataRequired = [];
|
|
1036
|
+
Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
|
|
1037
|
+
keys.add(key);
|
|
1038
|
+
formDataRequired.push(key);
|
|
1039
|
+
});
|
|
930
1040
|
keys.forEach((key) => {
|
|
931
1041
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
932
1042
|
rootSchema,
|
|
933
1043
|
_recurseList,
|
|
934
1044
|
experimental_defaultFormStateBehavior,
|
|
935
1045
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
936
|
-
parentDefaults:
|
|
937
|
-
rawFormData:
|
|
1046
|
+
parentDefaults: get8(defaults, [key]),
|
|
1047
|
+
rawFormData: get8(formData, [key]),
|
|
938
1048
|
required: schema.required?.includes(key)
|
|
939
1049
|
});
|
|
940
1050
|
maybeAddDefaultToObject(
|
|
@@ -975,7 +1085,7 @@
|
|
|
975
1085
|
_recurseList,
|
|
976
1086
|
experimental_defaultFormStateBehavior,
|
|
977
1087
|
rawFormData: item,
|
|
978
|
-
parentDefaults:
|
|
1088
|
+
parentDefaults: get8(defaults, [idx]),
|
|
979
1089
|
required
|
|
980
1090
|
});
|
|
981
1091
|
});
|
|
@@ -1092,27 +1202,27 @@
|
|
|
1092
1202
|
if (has3(newSchema, PROPERTIES_KEY)) {
|
|
1093
1203
|
const removeOldSchemaData = {};
|
|
1094
1204
|
if (has3(oldSchema, PROPERTIES_KEY)) {
|
|
1095
|
-
const properties =
|
|
1205
|
+
const properties = get8(oldSchema, PROPERTIES_KEY, {});
|
|
1096
1206
|
Object.keys(properties).forEach((key) => {
|
|
1097
1207
|
if (has3(data, key)) {
|
|
1098
1208
|
removeOldSchemaData[key] = void 0;
|
|
1099
1209
|
}
|
|
1100
1210
|
});
|
|
1101
1211
|
}
|
|
1102
|
-
const keys = Object.keys(
|
|
1212
|
+
const keys = Object.keys(get8(newSchema, PROPERTIES_KEY, {}));
|
|
1103
1213
|
const nestedData = {};
|
|
1104
1214
|
keys.forEach((key) => {
|
|
1105
|
-
const formValue =
|
|
1106
|
-
let oldKeyedSchema =
|
|
1107
|
-
let newKeyedSchema =
|
|
1215
|
+
const formValue = get8(data, key);
|
|
1216
|
+
let oldKeyedSchema = get8(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1217
|
+
let newKeyedSchema = get8(newSchema, [PROPERTIES_KEY, key], {});
|
|
1108
1218
|
if (has3(oldKeyedSchema, REF_KEY)) {
|
|
1109
1219
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
1110
1220
|
}
|
|
1111
1221
|
if (has3(newKeyedSchema, REF_KEY)) {
|
|
1112
1222
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1113
1223
|
}
|
|
1114
|
-
const oldSchemaTypeForKey =
|
|
1115
|
-
const newSchemaTypeForKey =
|
|
1224
|
+
const oldSchemaTypeForKey = get8(oldKeyedSchema, "type");
|
|
1225
|
+
const newSchemaTypeForKey = get8(newKeyedSchema, "type");
|
|
1116
1226
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1117
1227
|
if (has3(removeOldSchemaData, key)) {
|
|
1118
1228
|
delete removeOldSchemaData[key];
|
|
@@ -1129,17 +1239,17 @@
|
|
|
1129
1239
|
nestedData[key] = itemData;
|
|
1130
1240
|
}
|
|
1131
1241
|
} else {
|
|
1132
|
-
const newOptionDefault =
|
|
1133
|
-
const oldOptionDefault =
|
|
1242
|
+
const newOptionDefault = get8(newKeyedSchema, "default", NO_VALUE);
|
|
1243
|
+
const oldOptionDefault = get8(oldKeyedSchema, "default", NO_VALUE);
|
|
1134
1244
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1135
1245
|
if (oldOptionDefault === formValue) {
|
|
1136
1246
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1137
|
-
} else if (
|
|
1247
|
+
} else if (get8(newKeyedSchema, "readOnly") === true) {
|
|
1138
1248
|
removeOldSchemaData[key] = void 0;
|
|
1139
1249
|
}
|
|
1140
1250
|
}
|
|
1141
|
-
const newOptionConst =
|
|
1142
|
-
const oldOptionConst =
|
|
1251
|
+
const newOptionConst = get8(newKeyedSchema, "const", NO_VALUE);
|
|
1252
|
+
const oldOptionConst = get8(oldKeyedSchema, "const", NO_VALUE);
|
|
1143
1253
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1144
1254
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1145
1255
|
}
|
|
@@ -1151,9 +1261,9 @@
|
|
|
1151
1261
|
...removeOldSchemaData,
|
|
1152
1262
|
...nestedData
|
|
1153
1263
|
};
|
|
1154
|
-
} else if (
|
|
1155
|
-
let oldSchemaItems =
|
|
1156
|
-
let newSchemaItems =
|
|
1264
|
+
} else if (get8(oldSchema, "type") === "array" && get8(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1265
|
+
let oldSchemaItems = get8(oldSchema, "items");
|
|
1266
|
+
let newSchemaItems = get8(newSchema, "items");
|
|
1157
1267
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1158
1268
|
if (has3(oldSchemaItems, REF_KEY)) {
|
|
1159
1269
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
@@ -1161,10 +1271,10 @@
|
|
|
1161
1271
|
if (has3(newSchemaItems, REF_KEY)) {
|
|
1162
1272
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1163
1273
|
}
|
|
1164
|
-
const oldSchemaType =
|
|
1165
|
-
const newSchemaType =
|
|
1274
|
+
const oldSchemaType = get8(oldSchemaItems, "type");
|
|
1275
|
+
const newSchemaType = get8(newSchemaItems, "type");
|
|
1166
1276
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1167
|
-
const maxItems =
|
|
1277
|
+
const maxItems = get8(newSchema, "maxItems", -1);
|
|
1168
1278
|
if (newSchemaType === "object") {
|
|
1169
1279
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1170
1280
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1192,7 +1302,7 @@
|
|
|
1192
1302
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1193
1303
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1194
1304
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1195
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1305
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual4(item, _schema));
|
|
1196
1306
|
if (sameSchemaIndex === -1) {
|
|
1197
1307
|
return toIdSchemaInternal(
|
|
1198
1308
|
validator,
|
|
@@ -1206,10 +1316,10 @@
|
|
|
1206
1316
|
);
|
|
1207
1317
|
}
|
|
1208
1318
|
}
|
|
1209
|
-
if (ITEMS_KEY in schema && !
|
|
1319
|
+
if (ITEMS_KEY in schema && !get8(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1210
1320
|
return toIdSchemaInternal(
|
|
1211
1321
|
validator,
|
|
1212
|
-
|
|
1322
|
+
get8(schema, ITEMS_KEY),
|
|
1213
1323
|
idPrefix,
|
|
1214
1324
|
idSeparator,
|
|
1215
1325
|
id,
|
|
@@ -1222,7 +1332,7 @@
|
|
|
1222
1332
|
const idSchema = { $id };
|
|
1223
1333
|
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1224
1334
|
for (const name in schema.properties) {
|
|
1225
|
-
const field =
|
|
1335
|
+
const field = get8(schema, [PROPERTIES_KEY, name]);
|
|
1226
1336
|
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1227
1337
|
idSchema[name] = toIdSchemaInternal(
|
|
1228
1338
|
validator,
|
|
@@ -1233,7 +1343,7 @@
|
|
|
1233
1343
|
rootSchema,
|
|
1234
1344
|
// It's possible that formData is not an object -- this can happen if an
|
|
1235
1345
|
// array item has just been added, but not populated with data yet
|
|
1236
|
-
|
|
1346
|
+
get8(formData, [name]),
|
|
1237
1347
|
_recurseList
|
|
1238
1348
|
);
|
|
1239
1349
|
}
|
|
@@ -1246,7 +1356,7 @@
|
|
|
1246
1356
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1247
1357
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1248
1358
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1249
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1359
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual4(item, _schema));
|
|
1250
1360
|
if (sameSchemaIndex === -1) {
|
|
1251
1361
|
return toPathSchemaInternal(
|
|
1252
1362
|
validator,
|
|
@@ -1287,7 +1397,7 @@
|
|
|
1287
1397
|
});
|
|
1288
1398
|
} else if (PROPERTIES_KEY in schema) {
|
|
1289
1399
|
for (const property in schema.properties) {
|
|
1290
|
-
const field =
|
|
1400
|
+
const field = get8(schema, [PROPERTIES_KEY, property]);
|
|
1291
1401
|
pathSchema[property] = toPathSchemaInternal(
|
|
1292
1402
|
validator,
|
|
1293
1403
|
field,
|
|
@@ -1295,7 +1405,7 @@
|
|
|
1295
1405
|
rootSchema,
|
|
1296
1406
|
// It's possible that formData is not an object -- this can happen if an
|
|
1297
1407
|
// array item has just been added, but not populated with data yet
|
|
1298
|
-
|
|
1408
|
+
get8(formData, [property]),
|
|
1299
1409
|
_recurseList
|
|
1300
1410
|
);
|
|
1301
1411
|
}
|
|
@@ -1573,15 +1683,15 @@
|
|
|
1573
1683
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1574
1684
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1575
1685
|
if (Array.isArray(selected)) {
|
|
1576
|
-
return selected.filter((v) => !
|
|
1686
|
+
return selected.filter((v) => !isEqual4(v, value));
|
|
1577
1687
|
}
|
|
1578
|
-
return
|
|
1688
|
+
return isEqual4(value, selected) ? void 0 : selected;
|
|
1579
1689
|
}
|
|
1580
1690
|
function enumOptionsIsSelected(value, selected) {
|
|
1581
1691
|
if (Array.isArray(selected)) {
|
|
1582
|
-
return selected.some((sel) =>
|
|
1692
|
+
return selected.some((sel) => isEqual4(sel, value));
|
|
1583
1693
|
}
|
|
1584
|
-
return
|
|
1694
|
+
return isEqual4(selected, value);
|
|
1585
1695
|
}
|
|
1586
1696
|
|
|
1587
1697
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1628,7 +1738,7 @@
|
|
|
1628
1738
|
*/
|
|
1629
1739
|
getOrCreateErrorBlock(pathOfError) {
|
|
1630
1740
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1631
|
-
let errorBlock = hasPath ?
|
|
1741
|
+
let errorBlock = hasPath ? get8(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1632
1742
|
if (!errorBlock && pathOfError) {
|
|
1633
1743
|
errorBlock = {};
|
|
1634
1744
|
set3(this.errorSchema, pathOfError, errorBlock);
|
|
@@ -1654,7 +1764,7 @@
|
|
|
1654
1764
|
*/
|
|
1655
1765
|
addErrors(errorOrList, pathOfError) {
|
|
1656
1766
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1657
|
-
let errorsList =
|
|
1767
|
+
let errorsList = get8(errorBlock, ERRORS_KEY);
|
|
1658
1768
|
if (!Array.isArray(errorsList)) {
|
|
1659
1769
|
errorsList = [];
|
|
1660
1770
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -1818,7 +1928,7 @@
|
|
|
1818
1928
|
}
|
|
1819
1929
|
};
|
|
1820
1930
|
function mergeWidgetOptions(AWidget) {
|
|
1821
|
-
let MergedWidget =
|
|
1931
|
+
let MergedWidget = get8(AWidget, "MergedWidget");
|
|
1822
1932
|
if (!MergedWidget) {
|
|
1823
1933
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
1824
1934
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2222,12 +2332,12 @@
|
|
|
2222
2332
|
* @param hash - The hash value at which to map the schema
|
|
2223
2333
|
*/
|
|
2224
2334
|
addSchema(schema, hash) {
|
|
2225
|
-
const key =
|
|
2335
|
+
const key = get8(schema, ID_KEY, hash);
|
|
2226
2336
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2227
2337
|
const existing = this.schemaMap[key];
|
|
2228
2338
|
if (!existing) {
|
|
2229
2339
|
this.schemaMap[key] = identifiedSchema;
|
|
2230
|
-
} else if (!
|
|
2340
|
+
} else if (!isEqual4(existing, identifiedSchema)) {
|
|
2231
2341
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2232
2342
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2233
2343
|
throw new Error(
|
|
@@ -2249,7 +2359,7 @@
|
|
|
2249
2359
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2250
2360
|
*/
|
|
2251
2361
|
isValid(schema, _formData, rootSchema) {
|
|
2252
|
-
if (!
|
|
2362
|
+
if (!isEqual4(rootSchema, this.rootSchema)) {
|
|
2253
2363
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2254
2364
|
}
|
|
2255
2365
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2287,12 +2397,13 @@
|
|
|
2287
2397
|
|
|
2288
2398
|
// src/parser/schemaParser.ts
|
|
2289
2399
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2290
|
-
const
|
|
2400
|
+
const recurseRefs = [];
|
|
2401
|
+
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true, recurseRefs);
|
|
2291
2402
|
schemas.forEach((schema2) => {
|
|
2292
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
2403
|
+
const sameSchemaIndex = recurseList.findIndex((item) => isEqual4(item, schema2));
|
|
2293
2404
|
if (sameSchemaIndex === -1) {
|
|
2294
2405
|
recurseList.push(schema2);
|
|
2295
|
-
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
2406
|
+
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true, recurseRefs);
|
|
2296
2407
|
allOptions.forEach((s) => {
|
|
2297
2408
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
2298
2409
|
forEach(schema2[PROPERTIES_KEY], (value) => {
|
|
@@ -2366,6 +2477,7 @@
|
|
|
2366
2477
|
exports.getFirstMatchingOption = getFirstMatchingOption;
|
|
2367
2478
|
exports.getInputProps = getInputProps;
|
|
2368
2479
|
exports.getMatchingOption = getMatchingOption;
|
|
2480
|
+
exports.getOptionMatchingSimpleDiscriminator = getOptionMatchingSimpleDiscriminator;
|
|
2369
2481
|
exports.getSchemaType = getSchemaType;
|
|
2370
2482
|
exports.getSubmitButtonOptions = getSubmitButtonOptions;
|
|
2371
2483
|
exports.getTemplate = getTemplate;
|