@rjsf/utils 5.6.2 → 5.7.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.
@@ -22,6 +22,7 @@ var jsxRuntime = require('react/jsx-runtime');
22
22
  var react = require('react');
23
23
  var ReactIs = require('react-is');
24
24
  var toPath = require('lodash/toPath');
25
+ var forEach = require('lodash/forEach');
25
26
 
26
27
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
27
28
 
@@ -43,6 +44,7 @@ var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
43
44
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
44
45
  var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
45
46
  var toPath__default = /*#__PURE__*/_interopDefaultLegacy(toPath);
47
+ var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
46
48
 
47
49
  /** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
48
50
  * the type `object` but is NOT null, an array or a File.
@@ -186,6 +188,7 @@ var DEPENDENCIES_KEY = 'dependencies';
186
188
  var ENUM_KEY = 'enum';
187
189
  var ERRORS_KEY = '__errors';
188
190
  var ID_KEY = '$id';
191
+ var IF_KEY = 'if';
189
192
  var ITEMS_KEY = 'items';
190
193
  var NAME_KEY = '$name';
191
194
  var ONE_OF_KEY = 'oneOf';
@@ -443,6 +446,23 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
443
446
  return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
444
447
  }
445
448
 
449
+ /** Returns the `discriminator.propertyName` when defined in the `schema` if it is a string. A warning is generated when
450
+ * it is not a string. Returns `undefined` when a valid discriminator is not present.
451
+ *
452
+ * @param schema - The schema from which the discriminator is potentially obtained
453
+ * @returns - The `discriminator.propertyName` if it exists in the schema, otherwise `undefined`
454
+ */
455
+ function getDiscriminatorFieldFromSchema(schema) {
456
+ var discriminator;
457
+ var maybeString = get__default["default"](schema, 'discriminator.propertyName', undefined);
458
+ if (isString__default["default"](maybeString)) {
459
+ discriminator = maybeString;
460
+ } else if (maybeString !== undefined) {
461
+ console.warn("Expecting discriminator to be a string, got \"" + typeof maybeString + "\" instead");
462
+ }
463
+ return discriminator;
464
+ }
465
+
446
466
  /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
447
467
  * create a schema, it is useful to know what type to use based on the data we are defining.
448
468
  *
@@ -532,82 +552,164 @@ var _excluded$1 = ["if", "then", "else"],
532
552
  _excluded3 = ["allOf"],
533
553
  _excluded4 = ["dependencies"],
534
554
  _excluded5 = ["oneOf"];
555
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
556
+ * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
557
+ * potentially recursive resolution.
558
+ *
559
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
560
+ * @param schema - The schema for which retrieving a schema is desired
561
+ * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
562
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
563
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
564
+ */
565
+ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
566
+ if (rootSchema === void 0) {
567
+ rootSchema = {};
568
+ }
569
+ return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
570
+ }
535
571
  /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
536
- * with the rest of the schema
572
+ * with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
573
+ * conditions will be returned.
537
574
  *
538
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that is used to detect valid schema conditions
575
+ * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
539
576
  * @param schema - The schema for which resolving a condition is desired
540
577
  * @param rootSchema - The root schema that will be forwarded to all the APIs
578
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and
579
+ * dependencies as a list of schemas
541
580
  * @param [formData] - The current formData to assist retrieving a schema
542
- * @returns - A schema with the appropriate condition resolved
581
+ * @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
543
582
  */
544
- function resolveCondition(validator, schema, rootSchema, formData) {
583
+ function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
545
584
  var expression = schema["if"],
546
585
  then = schema.then,
547
586
  otherwise = schema["else"],
548
587
  resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
549
- var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
550
- if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
551
- return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
588
+ var conditionValue = validator.isValid(expression, formData, rootSchema);
589
+ var resolvedSchemas = [resolvedSchemaLessConditional];
590
+ var schemas = [];
591
+ if (expandAllBranches) {
592
+ if (then && typeof then !== 'boolean') {
593
+ schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches));
594
+ }
595
+ if (otherwise && typeof otherwise !== 'boolean') {
596
+ schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches));
597
+ }
598
+ } else {
599
+ var conditionalSchema = conditionValue ? then : otherwise;
600
+ if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
601
+ schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches));
602
+ }
603
+ }
604
+ if (schemas.length) {
605
+ resolvedSchemas = schemas.map(function (s) {
606
+ return mergeSchemas(resolvedSchemaLessConditional, s);
607
+ });
552
608
  }
553
- return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
609
+ return resolvedSchemas.flatMap(function (s) {
610
+ return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
611
+ });
612
+ }
613
+ /** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
614
+ * `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
615
+ * From those lists, build a matrix for each `xxxOf` where there is more than one schema for a row in the list of lists.
616
+ *
617
+ * For example:
618
+ * - If there are three xxxOf rows (A, B, C) and they have been resolved such that there is only one A, two B and three
619
+ * C schemas then:
620
+ * - The permutation for the first row is `[[A]]`
621
+ * - The permutations for the second row are `[[A,B1], [A,B2]]`
622
+ * - The permutations for the third row are `[[A,B1,C1], [A,B1,C2], [A,B1,C3], [A,B2,C1], [A,B2,C2], [A,B2,C3]]`
623
+ *
624
+ * @param listOfLists - The list of lists of elements that represent the allOf, anyOf or oneOf resolved values in order
625
+ * @returns - The list of all permutations of schemas for a set of `xxxOf`s
626
+ */
627
+ function getAllPermutationsOfXxxOf(listOfLists) {
628
+ var allPermutations = listOfLists.reduce(function (permutations, list) {
629
+ // When there are more than one set of schemas for a row, duplicate the set of permutations and add in the values
630
+ if (list.length > 1) {
631
+ return list.flatMap(function (element) {
632
+ return times__default["default"](permutations.length, function (i) {
633
+ return [].concat(permutations[i]).concat(element);
634
+ });
635
+ });
636
+ }
637
+ // Otherwise just push in the single value into the current set of permutations
638
+ permutations.forEach(function (permutation) {
639
+ return permutation.push(list[0]);
640
+ });
641
+ return permutations;
642
+ }, [[]] // Start with an empty list
643
+ );
644
+
645
+ return allPermutations;
554
646
  }
555
- /** Resolves references and dependencies within a schema and its 'allOf' children.
556
- * Called internally by retrieveSchema.
647
+ /** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
648
+ * down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
649
+ * `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
557
650
  *
558
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
651
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
559
652
  * @param schema - The schema for which resolving a schema is desired
560
- * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
653
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
654
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
655
+ * as a list of schemas
561
656
  * @param [formData] - The current formData, if any, to assist retrieving a schema
562
- * @returns - The schema having its references and dependencies resolved
657
+ * @returns - The list of schemas having its references, dependencies and allOf schemas resolved
563
658
  */
564
- function resolveSchema(validator, schema, rootSchema, formData) {
565
- if (rootSchema === void 0) {
566
- rootSchema = {};
567
- }
659
+ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
568
660
  if (REF_KEY in schema) {
569
- return resolveReference(validator, schema, rootSchema, formData);
661
+ return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
570
662
  }
571
663
  if (DEPENDENCIES_KEY in schema) {
572
- var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
573
- return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
664
+ var resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
665
+ return resolvedSchemas.flatMap(function (s) {
666
+ return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
667
+ });
574
668
  }
575
- if (ALL_OF_KEY in schema) {
576
- return _extends({}, schema, {
577
- allOf: schema.allOf.map(function (allOfSubschema) {
578
- return retrieveSchema(validator, allOfSubschema, rootSchema, formData);
579
- })
669
+ if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
670
+ var allOfSchemaElements = schema.allOf.map(function (allOfSubschema) {
671
+ return retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches);
672
+ });
673
+ var allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
674
+ return allPermutations.map(function (permutation) {
675
+ return _extends({}, schema, {
676
+ allOf: permutation
677
+ });
580
678
  });
581
679
  }
582
- // No $ref or dependencies attribute found, returning the original schema.
583
- return schema;
680
+ // No $ref or dependencies or allOf attribute was found, returning the original schema.
681
+ return [schema];
584
682
  }
585
- /** Resolves references within a schema and its 'allOf' children.
683
+ /** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes
684
+ * the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call.
586
685
  *
587
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
686
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
588
687
  * @param schema - The schema for which resolving a reference is desired
589
688
  * @param rootSchema - The root schema that will be forwarded to all the APIs
689
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
690
+ * as a list of schemas
590
691
  * @param [formData] - The current formData, if any, to assist retrieving a schema
591
- * @returns - The schema having its references resolved
692
+ * @returns - The list schemas retrieved after having all references resolved
592
693
  */
593
- function resolveReference(validator, schema, rootSchema, formData) {
594
- // Retrieve the referenced schema definition.
595
- var $refSchema = findSchemaDefinition(schema.$ref, rootSchema);
694
+ function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
596
695
  // Drop the $ref property of the source schema.
597
- var localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
696
+ var $ref = schema.$ref,
697
+ localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
698
+ // Retrieve the referenced schema definition.
699
+ var refSchema = findSchemaDefinition($ref, rootSchema);
598
700
  // Update referenced schema definition with local schema properties.
599
- return retrieveSchema(validator, _extends({}, $refSchema, localSchema), rootSchema, formData);
701
+ return retrieveSchemaInternal(validator, _extends({}, refSchema, localSchema), rootSchema, formData, expandAllBranches);
600
702
  }
601
703
  /** Creates new 'properties' items for each key in the `formData`
602
704
  *
603
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used when necessary
705
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
604
706
  * @param theSchema - The schema for which the existing additional properties is desired
605
707
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
606
708
  * @param [aFormData] - The current formData, if any, to assist retrieving a schema
607
709
  * @returns - The updated schema with additional properties stubbed
608
710
  */
609
711
  function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
610
- // Clone the schema so we don't ruin the consumer's original
712
+ // Clone the schema so that we don't ruin the consumer's original
611
713
  var schema = _extends({}, theSchema, {
612
714
  properties: _extends({}, theSchema.properties)
613
715
  });
@@ -647,98 +749,155 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
647
749
  });
648
750
  return schema;
649
751
  }
650
- /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
651
- * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
652
- * potentially recursive resolution.
752
+ /** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties,
753
+ * references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData`
754
+ * that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches
755
+ * of the schema and its references, conditions and dependencies are returned.
653
756
  *
654
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
757
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
655
758
  * @param schema - The schema for which retrieving a schema is desired
656
- * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
759
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
657
760
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
658
- * @returns - The schema having its conditions, additional properties, references and dependencies resolved
761
+ * @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
762
+ * dependencies as a list of schemas
763
+ * @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
764
+ * resolved. Multiple schemas may be returned if `expandAllBranches` is true.
659
765
  */
660
- function retrieveSchema(validator, schema, rootSchema, rawFormData) {
661
- if (rootSchema === void 0) {
662
- rootSchema = {};
766
+ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches) {
767
+ if (expandAllBranches === void 0) {
768
+ expandAllBranches = false;
663
769
  }
664
770
  if (!isObject(schema)) {
665
- return {};
771
+ return [{}];
666
772
  }
667
- var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
668
- if ('if' in schema) {
669
- return resolveCondition(validator, schema, rootSchema, rawFormData);
670
- }
671
- var formData = rawFormData || {};
672
- if (ALL_OF_KEY in schema) {
673
- try {
674
- resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
675
- deep: false
676
- });
677
- } catch (e) {
678
- console.warn('could not merge subschemas in allOf:\n', e);
679
- var _resolvedSchema = resolvedSchema,
680
- resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
681
- return resolvedSchemaWithoutAllOf;
773
+ var resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
774
+ return resolvedSchemas.flatMap(function (s) {
775
+ var resolvedSchema = s;
776
+ if (IF_KEY in resolvedSchema) {
777
+ return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
682
778
  }
779
+ if (ALL_OF_KEY in schema) {
780
+ try {
781
+ resolvedSchema = mergeAllOf__default["default"](s, {
782
+ deep: false
783
+ });
784
+ } catch (e) {
785
+ console.warn('could not merge subschemas in allOf:\n', e);
786
+ var _resolvedSchema = resolvedSchema,
787
+ resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
788
+ return resolvedSchemaWithoutAllOf;
789
+ }
790
+ }
791
+ var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
792
+ if (hasAdditionalProperties) {
793
+ return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
794
+ }
795
+ return resolvedSchema;
796
+ });
797
+ }
798
+ /** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from
799
+ * `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL
800
+ * options are retrieved and returned.
801
+ *
802
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
803
+ * @param schema - The schema for which retrieving a schema is desired
804
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
805
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
806
+ * as a list of schemas
807
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema, defaults to an empty object
808
+ * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
809
+ */
810
+ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
811
+ var anyOrOneOf;
812
+ if (Array.isArray(schema.oneOf)) {
813
+ anyOrOneOf = schema.oneOf;
814
+ } else if (Array.isArray(schema.anyOf)) {
815
+ anyOrOneOf = schema.anyOf;
816
+ }
817
+ if (anyOrOneOf) {
818
+ // Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
819
+ var formData = rawFormData === undefined && expandAllBranches ? {} : rawFormData;
820
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
821
+ anyOrOneOf = anyOrOneOf.map(function (s) {
822
+ if (REF_KEY in s) {
823
+ // For this ref situation, don't expand all branches and just pick the first/only schema result
824
+ return resolveReference(validator, s, rootSchema, false, formData)[0];
825
+ }
826
+ return s;
827
+ });
828
+ // Call this to trigger the set of isValid() calls that the schema parser will need
829
+ var option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
830
+ if (expandAllBranches) {
831
+ return anyOrOneOf;
832
+ }
833
+ schema = anyOrOneOf[option];
683
834
  }
684
- var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
685
- if (hasAdditionalProperties) {
686
- return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
687
- }
688
- return resolvedSchema;
835
+ return [schema];
689
836
  }
690
- /** Resolves dependencies within a schema and its 'allOf' children.
837
+ /** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
838
+ * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
691
839
  *
692
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
840
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
693
841
  * @param schema - The schema for which resolving a dependency is desired
694
842
  * @param rootSchema - The root schema that will be forwarded to all the APIs
843
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
844
+ * as a list of schemas
695
845
  * @param [formData] - The current formData, if any, to assist retrieving a schema
696
- * @returns - The schema with its dependencies resolved
846
+ * @returns - The list of schemas with their dependencies resolved
697
847
  */
698
- function resolveDependencies(validator, schema, rootSchema, formData) {
848
+ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
699
849
  // Drop the dependencies from the source schema.
700
850
  var dependencies = schema.dependencies,
701
851
  remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded4);
702
- var resolvedSchema = remainingSchema;
703
- if (Array.isArray(resolvedSchema.oneOf)) {
704
- resolvedSchema = resolvedSchema.oneOf[getFirstMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
705
- } else if (Array.isArray(resolvedSchema.anyOf)) {
706
- resolvedSchema = resolvedSchema.anyOf[getFirstMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
707
- }
708
- return processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData);
852
+ var resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
853
+ return resolvedSchemas.flatMap(function (resolvedSchema) {
854
+ return processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData);
855
+ });
709
856
  }
710
- /** Processes all the `dependencies` recursively into the `resolvedSchema` as needed
857
+ /** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
858
+ * `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
711
859
  *
712
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
860
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
713
861
  * @param dependencies - The set of dependencies that needs to be processed
714
862
  * @param resolvedSchema - The schema for which processing dependencies is desired
715
863
  * @param rootSchema - The root schema that will be forwarded to all the APIs
864
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
865
+ * as a list of schemas
716
866
  * @param [formData] - The current formData, if any, to assist retrieving a schema
717
867
  * @returns - The schema with the `dependencies` resolved into it
718
868
  */
719
- function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
720
- var schema = resolvedSchema;
869
+ function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
870
+ var schemas = [resolvedSchema];
721
871
  // Process dependencies updating the local schema properties as appropriate.
722
- for (var dependencyKey in dependencies) {
872
+ var _loop = function _loop() {
723
873
  // Skip this dependency if its trigger property is not present.
724
- if (get__default["default"](formData, [dependencyKey]) === undefined) {
725
- continue;
874
+ if (!expandAllBranches && get__default["default"](formData, [dependencyKey]) === undefined) {
875
+ return "continue";
726
876
  }
727
877
  // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
728
- if (schema.properties && !(dependencyKey in schema.properties)) {
729
- continue;
878
+ if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
879
+ return "continue";
730
880
  }
731
881
  var _splitKeyElementFromO = splitKeyElementFromObject(dependencyKey, dependencies),
732
882
  remainingDependencies = _splitKeyElementFromO[0],
733
883
  dependencyValue = _splitKeyElementFromO[1];
734
884
  if (Array.isArray(dependencyValue)) {
735
- schema = withDependentProperties(schema, dependencyValue);
885
+ schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
736
886
  } else if (isObject(dependencyValue)) {
737
- schema = withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData);
887
+ schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData);
738
888
  }
739
- return processDependencies(validator, remainingDependencies, schema, rootSchema, formData);
889
+ return {
890
+ v: schemas.flatMap(function (schema) {
891
+ return processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData);
892
+ })
893
+ };
894
+ };
895
+ for (var dependencyKey in dependencies) {
896
+ var _ret = _loop();
897
+ if (_ret === "continue") continue;
898
+ if (typeof _ret === "object") return _ret.v;
740
899
  }
741
- return schema;
900
+ return schemas;
742
901
  }
743
902
  /** Updates a schema with additionally required properties added
744
903
  *
@@ -755,45 +914,57 @@ function withDependentProperties(schema, additionallyRequired) {
755
914
  required: required
756
915
  });
757
916
  }
758
- /** Merges a dependent schema into the `schema` dealing with oneOfs and references
917
+ /** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
918
+ * down to the `retrieveSchemaInternal()`, `resolveReference()` and `withExactlyOneSubschema()` helper calls.
759
919
  *
760
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
920
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
761
921
  * @param schema - The schema for which resolving a dependent schema is desired
762
922
  * @param rootSchema - The root schema that will be forwarded to all the APIs
763
923
  * @param dependencyKey - The key name of the dependency
764
924
  * @param dependencyValue - The potentially dependent schema
765
- * @param formData- The current formData to assist retrieving a schema
766
- * @returns - The schema with the dependent schema resolved into it
767
- */
768
- function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
769
- var _retrieveSchema = retrieveSchema(validator, dependencyValue, rootSchema, formData),
770
- oneOf = _retrieveSchema.oneOf,
771
- dependentSchema = _objectWithoutPropertiesLoose(_retrieveSchema, _excluded5);
772
- schema = mergeSchemas(schema, dependentSchema);
773
- // Since it does not contain oneOf, we return the original schema.
774
- if (oneOf === undefined) {
775
- return schema;
776
- }
777
- // Resolve $refs inside oneOf.
778
- var resolvedOneOf = oneOf.map(function (subschema) {
779
- if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
780
- return subschema;
925
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
926
+ * as a list of schemas
927
+ * @param [formData]- The current formData to assist retrieving a schema
928
+ * @returns - The list of schemas with the dependent schema resolved into them
929
+ */
930
+ function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
931
+ var dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
932
+ return dependentSchemas.flatMap(function (dependent) {
933
+ var oneOf = dependent.oneOf,
934
+ dependentSchema = _objectWithoutPropertiesLoose(dependent, _excluded5);
935
+ schema = mergeSchemas(schema, dependentSchema);
936
+ // Since it does not contain oneOf, we return the original schema.
937
+ if (oneOf === undefined) {
938
+ return schema;
781
939
  }
782
- return resolveReference(validator, subschema, rootSchema, formData);
940
+ // Resolve $refs inside oneOf.
941
+ var resolvedOneOfs = oneOf.map(function (subschema) {
942
+ if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
943
+ return [subschema];
944
+ }
945
+ return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
946
+ });
947
+ var allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
948
+ return allPermutations.flatMap(function (resolvedOneOf) {
949
+ return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData);
950
+ });
783
951
  });
784
- return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, formData);
785
952
  }
786
- /** Returns a `schema` with the best choice from the `oneOf` options merged into it
953
+ /** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
954
+ * true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to
955
+ * the `retrieveSchemaInternal()` helper call.
787
956
  *
788
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used to validate oneOf options
957
+ * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
789
958
  * @param schema - The schema for which resolving a oneOf subschema is desired
790
959
  * @param rootSchema - The root schema that will be forwarded to all the APIs
791
960
  * @param dependencyKey - The key name of the oneOf dependency
792
961
  * @param oneOf - The list of schemas representing the oneOf options
962
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
963
+ * as a list of schemas
793
964
  * @param [formData] - The current formData to assist retrieving a schema
794
- * @returns The schema with the best choice of oneOf schemas merged into
965
+ * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
795
966
  */
796
- function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
967
+ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
797
968
  var validSubschemas = oneOf.filter(function (subschema) {
798
969
  if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
799
970
  return false;
@@ -805,21 +976,26 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
805
976
  type: 'object',
806
977
  properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
807
978
  };
808
- return validator.isValid(conditionSchema, formData, rootSchema);
979
+ return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
809
980
  }
810
981
  return false;
811
982
  });
812
- if (validSubschemas.length !== 1) {
983
+ if (!expandAllBranches && validSubschemas.length !== 1) {
813
984
  console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
814
- return schema;
815
- }
816
- var subschema = validSubschemas[0];
817
- var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
818
- dependentSubschema = _splitKeyElementFromO2[0];
819
- var dependentSchema = _extends({}, subschema, {
820
- properties: dependentSubschema
985
+ return [schema];
986
+ }
987
+ return validSubschemas.flatMap(function (s) {
988
+ var subschema = s;
989
+ var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
990
+ dependentSubschema = _splitKeyElementFromO2[0];
991
+ var dependentSchema = _extends({}, subschema, {
992
+ properties: dependentSubschema
993
+ });
994
+ var schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches);
995
+ return schemas.map(function (s) {
996
+ return mergeSchemas(schema, s);
997
+ });
821
998
  });
822
- return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
823
999
  }
824
1000
 
825
1001
  /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
@@ -1143,10 +1319,11 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
1143
1319
  }
1144
1320
  return {};
1145
1321
  }
1146
- /** Either add `computedDefault` at `key` into `obj` or not add it based on its value and the value of
1147
- * `includeUndefinedValues`. Generally undefined `computedDefault` values are added only when `includeUndefinedValues`
1148
- * is either true or "excludeObjectChildren". If `includeUndefinedValues` is false, then non-undefined and
1149
- * non-empty-object values will be added.
1322
+ /** Either add `computedDefault` at `key` into `obj` or not add it based on its value, the value of
1323
+ * `includeUndefinedValues`, the value of `emptyObjectFields` and if its parent field is required. Generally undefined
1324
+ * `computedDefault` values are added only when `includeUndefinedValues` is either true/"excludeObjectChildren". If `
1325
+ * includeUndefinedValues` is false and `emptyObjectFields` is not "skipDefaults", then non-undefined and non-empty-object
1326
+ * values will be added based on certain conditions.
1150
1327
  *
1151
1328
  * @param obj - The object into which the computed default may be added
1152
1329
  * @param key - The key into the object at which the computed default may be added
@@ -1156,22 +1333,38 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
1156
1333
  * false when computing defaults for any nested object properties. If "allowEmptyObject", prevents undefined
1157
1334
  * values in this object while allow the object itself to be empty and passing `includeUndefinedValues` as
1158
1335
  * false when computing defaults for any nested object properties.
1336
+ * @param isParentRequired - The optional boolean that indicates whether the parent field is required
1159
1337
  * @param requiredFields - The list of fields that are required
1338
+ * @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
1339
+ * default form state behavior
1160
1340
  */
1161
- function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, requiredFields) {
1341
+ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields, experimental_defaultFormStateBehavior) {
1162
1342
  if (requiredFields === void 0) {
1163
1343
  requiredFields = [];
1164
1344
  }
1345
+ if (experimental_defaultFormStateBehavior === void 0) {
1346
+ experimental_defaultFormStateBehavior = {};
1347
+ }
1348
+ var _experimental_default = experimental_defaultFormStateBehavior,
1349
+ _experimental_default2 = _experimental_default.emptyObjectFields,
1350
+ emptyObjectFields = _experimental_default2 === void 0 ? 'populateAllDefaults' : _experimental_default2;
1165
1351
  if (includeUndefinedValues) {
1166
1352
  obj[key] = computedDefault;
1167
- } else if (isObject(computedDefault)) {
1168
- // Store computedDefault if it's a non-empty object (e.g. not {})
1169
- if (!isEmpty__default["default"](computedDefault) || requiredFields.includes(key)) {
1353
+ } else if (emptyObjectFields !== 'skipDefaults') {
1354
+ if (isObject(computedDefault)) {
1355
+ // Store computedDefault if it's a non-empty object(e.g. not {}) and satisfies certain conditions
1356
+ // Condition 1: If computedDefault is not empty or if the key is a required field
1357
+ // Condition 2: If the parent object is required or emptyObjectFields is not 'populateRequiredDefaults'
1358
+ if ((!isEmpty__default["default"](computedDefault) || requiredFields.includes(key)) && (isParentRequired || emptyObjectFields !== 'populateRequiredDefaults')) {
1359
+ obj[key] = computedDefault;
1360
+ }
1361
+ } else if (
1362
+ // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
1363
+ // Condition 1: computedDefault is not undefined
1364
+ // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
1365
+ computedDefault !== undefined && (emptyObjectFields === 'populateAllDefaults' || requiredFields.includes(key))) {
1170
1366
  obj[key] = computedDefault;
1171
1367
  }
1172
- } else if (computedDefault !== undefined) {
1173
- // Store computedDefault if it's a defined primitive (e.g. true)
1174
- obj[key] = computedDefault;
1175
1368
  }
1176
1369
  }
1177
1370
  /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
@@ -1179,29 +1372,39 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
1179
1372
  *
1180
1373
  * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
1181
1374
  * @param rawSchema - The schema for which the default state is desired
1182
- * @param [parentDefaults] - Any defaults provided by the parent field in the schema
1183
- * @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
1184
- * @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
1185
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1375
+ * @param [props] - Optional props for this function
1376
+ * @param [props.parentDefaults] - Any defaults provided by the parent field in the schema
1377
+ * @param [props.rootSchema] - The options root schema, used to primarily to look up `$ref`s
1378
+ * @param [props.rawFormData] - The current formData, if any, onto which to provide any missing defaults
1379
+ * @param [props.includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1186
1380
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1187
1381
  * false when computing defaults for any nested object properties.
1188
- * @param [_recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
1382
+ * @param [props._recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
1383
+ * @param [props.experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1384
+ * @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
1189
1385
  * @returns - The resulting `formData` with all the defaults provided
1190
1386
  */
1191
- function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues, _recurseList) {
1192
- if (rootSchema === void 0) {
1193
- rootSchema = {};
1194
- }
1195
- if (includeUndefinedValues === void 0) {
1196
- includeUndefinedValues = false;
1197
- }
1198
- if (_recurseList === void 0) {
1199
- _recurseList = [];
1200
- }
1387
+ function computeDefaults(validator, rawSchema, _temp) {
1388
+ var _ref = _temp === void 0 ? {} : _temp,
1389
+ parentDefaults = _ref.parentDefaults,
1390
+ rawFormData = _ref.rawFormData,
1391
+ _ref$rootSchema = _ref.rootSchema,
1392
+ rootSchema = _ref$rootSchema === void 0 ? {} : _ref$rootSchema,
1393
+ _ref$includeUndefined = _ref.includeUndefinedValues,
1394
+ includeUndefinedValues = _ref$includeUndefined === void 0 ? false : _ref$includeUndefined,
1395
+ _ref$_recurseList = _ref._recurseList,
1396
+ _recurseList = _ref$_recurseList === void 0 ? [] : _ref$_recurseList,
1397
+ _ref$experimental_def = _ref.experimental_defaultFormStateBehavior,
1398
+ experimental_defaultFormStateBehavior = _ref$experimental_def === void 0 ? undefined : _ref$experimental_def,
1399
+ _ref$required = _ref.required,
1400
+ required = _ref$required === void 0 ? false : _ref$required;
1201
1401
  var formData = isObject(rawFormData) ? rawFormData : {};
1202
1402
  var schema = isObject(rawSchema) ? rawSchema : {};
1203
1403
  // Compute the defaults recursively: give highest priority to deepest nodes.
1204
1404
  var defaults = parentDefaults;
1405
+ // If we get a new schema, then we need to recompute defaults again for the new schema found.
1406
+ var schemaToCompute = null;
1407
+ var updatedRecurseList = _recurseList;
1205
1408
  if (isObject(defaults) && isObject(schema["default"])) {
1206
1409
  // For object defaults, only override parent defaults that are defined in
1207
1410
  // schema.default.
@@ -1212,40 +1415,68 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1212
1415
  var refName = schema[REF_KEY];
1213
1416
  // Use referenced schema defaults for this node.
1214
1417
  if (!_recurseList.includes(refName)) {
1215
- var refSchema = findSchemaDefinition(refName, rootSchema);
1216
- return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList.concat(refName));
1418
+ updatedRecurseList = _recurseList.concat(refName);
1419
+ schemaToCompute = findSchemaDefinition(refName, rootSchema);
1217
1420
  }
1218
1421
  } else if (DEPENDENCIES_KEY in schema) {
1219
- var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
1220
- return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList);
1422
+ var resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
1423
+ schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies
1221
1424
  } else if (isFixedItems(schema)) {
1222
1425
  defaults = schema.items.map(function (itemSchema, idx) {
1223
- return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues, _recurseList);
1426
+ return computeDefaults(validator, itemSchema, {
1427
+ rootSchema: rootSchema,
1428
+ includeUndefinedValues: includeUndefinedValues,
1429
+ _recurseList: _recurseList,
1430
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1431
+ parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,
1432
+ rawFormData: formData
1433
+ });
1224
1434
  });
1225
1435
  } else if (ONE_OF_KEY in schema) {
1226
1436
  if (schema.oneOf.length === 0) {
1227
1437
  return undefined;
1228
1438
  }
1229
- schema = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, 0)];
1439
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
1440
+ schemaToCompute = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, 0, discriminator)];
1230
1441
  } else if (ANY_OF_KEY in schema) {
1231
1442
  if (schema.anyOf.length === 0) {
1232
1443
  return undefined;
1233
1444
  }
1234
- schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0)];
1445
+ var _discriminator = getDiscriminatorFieldFromSchema(schema);
1446
+ schemaToCompute = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0, _discriminator)];
1447
+ }
1448
+ if (schemaToCompute) {
1449
+ return computeDefaults(validator, schemaToCompute, {
1450
+ rootSchema: rootSchema,
1451
+ includeUndefinedValues: includeUndefinedValues,
1452
+ _recurseList: updatedRecurseList,
1453
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1454
+ parentDefaults: defaults,
1455
+ rawFormData: formData
1456
+ });
1235
1457
  }
1236
- // Not defaults defined for this node, fallback to generic typed ones.
1237
- if (typeof defaults === 'undefined') {
1458
+ // No defaults defined for this node, fallback to generic typed ones.
1459
+ if (defaults === undefined) {
1238
1460
  defaults = schema["default"];
1239
1461
  }
1240
1462
  switch (getSchemaType(schema)) {
1241
- // We need to recur for object schema inner default values.
1463
+ // We need to recurse for object schema inner default values.
1242
1464
  case 'object':
1243
1465
  {
1244
1466
  var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
1467
+ var _schema$required;
1245
1468
  // Compute the defaults for this node, with the parent defaults we might
1246
1469
  // have from a previous run: defaults[key].
1247
- var computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === true, _recurseList);
1248
- maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, schema.required);
1470
+ var computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), {
1471
+ rootSchema: rootSchema,
1472
+ _recurseList: _recurseList,
1473
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1474
+ includeUndefinedValues: includeUndefinedValues === true,
1475
+ parentDefaults: get__default["default"](defaults, [key]),
1476
+ rawFormData: get__default["default"](formData, [key]),
1477
+ required: (_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(key)
1478
+ });
1479
+ maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, schema.required, experimental_defaultFormStateBehavior);
1249
1480
  return acc;
1250
1481
  }, {});
1251
1482
  if (schema.additionalProperties) {
@@ -1259,49 +1490,82 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1259
1490
  return keys.add(key);
1260
1491
  });
1261
1492
  }
1493
+ var formDataRequired;
1262
1494
  if (isObject(formData)) {
1495
+ formDataRequired = [];
1263
1496
  Object.keys(formData).filter(function (key) {
1264
1497
  return !schema.properties || !schema.properties[key];
1265
1498
  }).forEach(function (key) {
1266
- return keys.add(key);
1499
+ keys.add(key);
1500
+ formDataRequired.push(key);
1267
1501
  });
1268
1502
  }
1269
1503
  keys.forEach(function (key) {
1270
- var computedDefault = computeDefaults(validator, additionalPropertiesSchema, get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === true, _recurseList);
1271
- maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues);
1504
+ var _schema$required2;
1505
+ var computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
1506
+ rootSchema: rootSchema,
1507
+ _recurseList: _recurseList,
1508
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1509
+ includeUndefinedValues: includeUndefinedValues === true,
1510
+ parentDefaults: get__default["default"](defaults, [key]),
1511
+ rawFormData: get__default["default"](formData, [key]),
1512
+ required: (_schema$required2 = schema.required) === null || _schema$required2 === void 0 ? void 0 : _schema$required2.includes(key)
1513
+ });
1514
+ // Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop
1515
+ maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues, required, formDataRequired);
1272
1516
  });
1273
1517
  }
1274
1518
  return objectDefaults;
1275
1519
  }
1276
1520
  case 'array':
1277
- // Inject defaults into existing array defaults
1278
- if (Array.isArray(defaults)) {
1279
- defaults = defaults.map(function (item, idx) {
1280
- var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1281
- return computeDefaults(validator, schemaItem, item, rootSchema, undefined, undefined, _recurseList);
1282
- });
1283
- }
1284
- // Deeply inject defaults into already existing form data
1285
- if (Array.isArray(rawFormData)) {
1286
- var schemaItem = getInnerSchemaForArrayItem(schema);
1287
- defaults = rawFormData.map(function (item, idx) {
1288
- return computeDefaults(validator, schemaItem, get__default["default"](defaults, [idx]), rootSchema, item, undefined, _recurseList);
1289
- });
1290
- }
1291
- if (schema.minItems) {
1292
- if (!isMultiSelect(validator, schema, rootSchema)) {
1293
- var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1294
- if (schema.minItems > defaultsLength) {
1295
- var defaultEntries = defaults || [];
1296
- // populate the array with the defaults
1297
- var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1298
- var fillerDefault = fillerSchema["default"];
1299
- var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema, undefined, undefined, _recurseList));
1300
- // then fill up the rest with either the item default or empty, up to minItems
1301
- return defaultEntries.concat(fillerEntries);
1302
- }
1521
+ {
1522
+ // Inject defaults into existing array defaults
1523
+ if (Array.isArray(defaults)) {
1524
+ defaults = defaults.map(function (item, idx) {
1525
+ var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1526
+ return computeDefaults(validator, schemaItem, {
1527
+ rootSchema: rootSchema,
1528
+ _recurseList: _recurseList,
1529
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1530
+ parentDefaults: item
1531
+ });
1532
+ });
1303
1533
  }
1304
- return defaults ? defaults : [];
1534
+ // Deeply inject defaults into already existing form data
1535
+ if (Array.isArray(rawFormData)) {
1536
+ var schemaItem = getInnerSchemaForArrayItem(schema);
1537
+ defaults = rawFormData.map(function (item, idx) {
1538
+ return computeDefaults(validator, schemaItem, {
1539
+ rootSchema: rootSchema,
1540
+ _recurseList: _recurseList,
1541
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1542
+ rawFormData: item,
1543
+ parentDefaults: get__default["default"](defaults, [idx])
1544
+ });
1545
+ });
1546
+ }
1547
+ var ignoreMinItemsFlagSet = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) === 'requiredOnly';
1548
+ if (ignoreMinItemsFlagSet && !required) {
1549
+ // If no form data exists or defaults are set leave the field empty/non-existent, otherwise
1550
+ // return form data/defaults
1551
+ return defaults ? defaults : undefined;
1552
+ }
1553
+ var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1554
+ if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1555
+ return defaults ? defaults : [];
1556
+ }
1557
+ var defaultEntries = defaults || [];
1558
+ var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1559
+ var fillerDefault = fillerSchema["default"];
1560
+ // Calculate filler entries for remaining items (minItems - existing raw data/defaults)
1561
+ var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, {
1562
+ parentDefaults: fillerDefault,
1563
+ rootSchema: rootSchema,
1564
+ _recurseList: _recurseList,
1565
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior
1566
+ }));
1567
+ // then fill up the rest with either the item default or empty, up to minItems
1568
+ return defaultEntries.concat(fillerEntries);
1305
1569
  }
1306
1570
  }
1307
1571
  return defaults;
@@ -1316,9 +1580,10 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1316
1580
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1317
1581
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1318
1582
  * false when computing defaults for any nested object properties.
1583
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1319
1584
  * @returns - The resulting `formData` with all the defaults provided
1320
1585
  */
1321
- function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
1586
+ function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues, experimental_defaultFormStateBehavior) {
1322
1587
  if (includeUndefinedValues === void 0) {
1323
1588
  includeUndefinedValues = false;
1324
1589
  }
@@ -1326,8 +1591,13 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1326
1591
  throw new Error('Invalid schema: ' + theSchema);
1327
1592
  }
1328
1593
  var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1329
- var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1330
- if (typeof formData === 'undefined' || formData === null || typeof formData === 'number' && isNaN(formData)) {
1594
+ var defaults = computeDefaults(validator, schema, {
1595
+ rootSchema: rootSchema,
1596
+ includeUndefinedValues: includeUndefinedValues,
1597
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1598
+ rawFormData: formData
1599
+ });
1600
+ if (formData === undefined || formData === null || typeof formData === 'number' && isNaN(formData)) {
1331
1601
  // No form data? Use schema defaults.
1332
1602
  return defaults;
1333
1603
  }
@@ -1697,15 +1967,12 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
1697
1967
  }
1698
1968
  }
1699
1969
  var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ''), _pathSchema);
1700
- if (ONE_OF_KEY in schema) {
1701
- var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
1702
- var _schema2 = schema.oneOf[index];
1703
- return toPathSchemaInternal(validator, _schema2, name, rootSchema, formData, _recurseList);
1704
- }
1705
- if (ANY_OF_KEY in schema) {
1706
- var _index = getClosestMatchingOption(validator, rootSchema, formData, schema.anyOf, 0);
1707
- var _schema3 = schema.anyOf[_index];
1708
- return toPathSchemaInternal(validator, _schema3, name, rootSchema, formData, _recurseList);
1970
+ if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
1971
+ var xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
1972
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
1973
+ var index = getClosestMatchingOption(validator, rootSchema, formData, xxxOf, 0, discriminator);
1974
+ var _schema2 = xxxOf[index];
1975
+ pathSchema = _extends({}, pathSchema, toPathSchemaInternal(validator, _schema2, name, rootSchema, formData, _recurseList));
1709
1976
  }
1710
1977
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1711
1978
  set__default["default"](pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
@@ -1742,8 +2009,8 @@ function toPathSchema(validator, schema, name, rootSchema, formData) {
1742
2009
  }
1743
2010
 
1744
2011
  /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
1745
- * that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both the `validator`
1746
- * and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
2012
+ * that one does not have to explicitly pass the `validator`, `rootSchema`, or `experimental_defaultFormStateBehavior` to each method.
2013
+ * Since these generally do not change across a `Form`, this allows for providing a simplified set of APIs to the
1747
2014
  * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1748
2015
  */
1749
2016
  var SchemaUtils = /*#__PURE__*/function () {
@@ -1751,12 +2018,15 @@ var SchemaUtils = /*#__PURE__*/function () {
1751
2018
  *
1752
2019
  * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1753
2020
  * @param rootSchema - The root schema that will be forwarded to all the APIs
2021
+ * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
1754
2022
  */
1755
- function SchemaUtils(validator, rootSchema) {
2023
+ function SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior) {
1756
2024
  this.rootSchema = void 0;
1757
2025
  this.validator = void 0;
2026
+ this.experimental_defaultFormStateBehavior = void 0;
1758
2027
  this.rootSchema = rootSchema;
1759
2028
  this.validator = validator;
2029
+ this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
1760
2030
  }
1761
2031
  /** Returns the `ValidatorType` in the `SchemaUtilsType`
1762
2032
  *
@@ -1772,13 +2042,17 @@ var SchemaUtils = /*#__PURE__*/function () {
1772
2042
  *
1773
2043
  * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1774
2044
  * @param rootSchema - The root schema that will be compared against the current one
2045
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1775
2046
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1776
2047
  */;
1777
- _proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema) {
2048
+ _proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior) {
2049
+ if (experimental_defaultFormStateBehavior === void 0) {
2050
+ experimental_defaultFormStateBehavior = {};
2051
+ }
1778
2052
  if (!validator || !rootSchema) {
1779
2053
  return false;
1780
2054
  }
1781
- return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema);
2055
+ return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
1782
2056
  }
1783
2057
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1784
2058
  * computed to have defaults provided in the `schema`.
@@ -1794,7 +2068,7 @@ var SchemaUtils = /*#__PURE__*/function () {
1794
2068
  if (includeUndefinedValues === void 0) {
1795
2069
  includeUndefinedValues = false;
1796
2070
  }
1797
- return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues);
2071
+ return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues, this.experimental_defaultFormStateBehavior);
1798
2072
  }
1799
2073
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1800
2074
  * should be displayed in a UI.
@@ -1947,10 +2221,14 @@ var SchemaUtils = /*#__PURE__*/function () {
1947
2221
  *
1948
2222
  * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1949
2223
  * @param rootSchema - The root schema that will be forwarded to all the APIs
2224
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1950
2225
  * @returns - An implementation of a `SchemaUtilsType` interface
1951
2226
  */
1952
- function createSchemaUtils(validator, rootSchema) {
1953
- return new SchemaUtils(validator, rootSchema);
2227
+ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior) {
2228
+ if (experimental_defaultFormStateBehavior === void 0) {
2229
+ experimental_defaultFormStateBehavior = {};
2230
+ }
2231
+ return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
1954
2232
  }
1955
2233
 
1956
2234
  /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
@@ -2505,6 +2783,32 @@ function getWidget(schema, widget, registeredWidgets) {
2505
2783
  throw new Error("No widget '" + widget + "' for type '" + type + "'");
2506
2784
  }
2507
2785
 
2786
+ /** JS has no built-in hashing function, so rolling our own
2787
+ * based on Java's hashing fn:
2788
+ * http://www.java2s.com/example/nodejs-utility-method/string-hash/hashcode-4dc2b.html
2789
+ *
2790
+ * @param string - The string for which to get the hash
2791
+ * @returns - The resulting hash of the string in hex format
2792
+ */
2793
+ function hashString(string) {
2794
+ var hash = 0;
2795
+ for (var i = 0; i < string.length; i += 1) {
2796
+ var chr = string.charCodeAt(i);
2797
+ hash = (hash << 5) - hash + chr;
2798
+ hash = hash & hash; // Convert to 32bit integer
2799
+ }
2800
+
2801
+ return hash.toString(16);
2802
+ }
2803
+ /** Stringifies the schema and returns the hash of the resulting string.
2804
+ *
2805
+ * @param schema - The schema for which the hash is desired
2806
+ * @returns - The string obtained from the hash of the stringified schema
2807
+ */
2808
+ function hashForSchema(schema) {
2809
+ return hashString(JSON.stringify(schema));
2810
+ }
2811
+
2508
2812
  /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
2509
2813
  * does, or false if it doesn't.
2510
2814
  *
@@ -3108,6 +3412,141 @@ exports.TranslatableString = void 0;
3108
3412
  TranslatableString["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
3109
3413
  })(exports.TranslatableString || (exports.TranslatableString = {}));
3110
3414
 
3415
+ /** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
3416
+ * `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
3417
+ * An instance of the object allows the caller to capture the schemas used in calls to the `isValid()` function. These
3418
+ * captured schema, along with the root schema used to construct the object are stored in the map of schemas keyed by
3419
+ * the hashed value of the schema. NOTE: After hashing the schema, an $id with the hash value is added to the
3420
+ * schema IF that schema doesn't already have an $id, prior to putting the schema into the map.
3421
+ */
3422
+ var ParserValidator = /*#__PURE__*/function () {
3423
+ /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
3424
+ * first.
3425
+ *
3426
+ * @param rootSchema - The root schema against which this validator will be executed
3427
+ */
3428
+ function ParserValidator(rootSchema) {
3429
+ /** The rootSchema provided during construction of the class */
3430
+ this.rootSchema = void 0;
3431
+ /** The map of schemas encountered by the ParserValidator */
3432
+ this.schemaMap = {};
3433
+ this.rootSchema = rootSchema;
3434
+ this.addSchema(rootSchema, hashForSchema(rootSchema));
3435
+ }
3436
+ /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
3437
+ * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
3438
+ * associated with it's `hash` for future use (by a schema compiler).
3439
+ *
3440
+ * @param schema - The schema which is to be added to the map
3441
+ * @param hash - The hash value at which to map the schema
3442
+ */
3443
+ var _proto = ParserValidator.prototype;
3444
+ _proto.addSchema = function addSchema(schema, hash) {
3445
+ var _extends2;
3446
+ var key = get__default["default"](schema, ID_KEY, hash);
3447
+ var identifiedSchema = _extends({}, schema, (_extends2 = {}, _extends2[ID_KEY] = key, _extends2));
3448
+ var existing = this.schemaMap[key];
3449
+ if (!existing) {
3450
+ this.schemaMap[key] = identifiedSchema;
3451
+ } else if (!isEqual__default["default"](existing, identifiedSchema)) {
3452
+ console.error('existing schema:', JSON.stringify(existing, null, 2));
3453
+ console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
3454
+ throw new Error("Two different schemas exist with the same key " + key + "! What a bad coincidence. If possible, try adding an $id to one of the schemas");
3455
+ }
3456
+ }
3457
+ /** Returns the current `schemaMap` to the caller
3458
+ */;
3459
+ _proto.getSchemaMap = function getSchemaMap() {
3460
+ return this.schemaMap;
3461
+ }
3462
+ /** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
3463
+ * the `rootSchema` is not the same as the root schema provided during construction.
3464
+ *
3465
+ * @param schema - The schema to record in the `schemaMap`
3466
+ * @param _formData - The formData parameter that is ignored
3467
+ * @param rootSchema - The root schema associated with the schema
3468
+ * @throws - Error when the given `rootSchema` differs from the root schema provided during construction
3469
+ */;
3470
+ _proto.isValid = function isValid(schema, _formData, rootSchema) {
3471
+ if (!isEqual__default["default"](rootSchema, this.rootSchema)) {
3472
+ throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
3473
+ }
3474
+ this.addSchema(schema, hashForSchema(schema));
3475
+ return false;
3476
+ }
3477
+ /** Implements the `ValidatorType` `rawValidation()` method to throw an error since it is never supposed to be called
3478
+ *
3479
+ * @param _schema - The schema parameter that is ignored
3480
+ * @param _formData - The formData parameter that is ignored
3481
+ */;
3482
+ _proto.rawValidation = function rawValidation(_schema, _formData) {
3483
+ throw new Error('Unexpectedly calling the `rawValidation()` method during schema parsing');
3484
+ }
3485
+ /** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
3486
+ *
3487
+ * @param _errorSchema - The error schema parameter that is ignored
3488
+ * @param _fieldPath - The field path parameter that is ignored
3489
+ */;
3490
+ _proto.toErrorList = function toErrorList(_errorSchema, _fieldPath) {
3491
+ throw new Error('Unexpectedly calling the `toErrorList()` method during schema parsing');
3492
+ }
3493
+ /** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
3494
+ * called
3495
+ *
3496
+ * @param _formData - The formData parameter that is ignored
3497
+ * @param _schema - The schema parameter that is ignored
3498
+ * @param _customValidate - The customValidate parameter that is ignored
3499
+ * @param _transformErrors - The transformErrors parameter that is ignored
3500
+ * @param _uiSchema - The uiSchema parameter that is ignored
3501
+ */;
3502
+ _proto.validateFormData = function validateFormData(_formData, _schema, _customValidate, _transformErrors, _uiSchema) {
3503
+ throw new Error('Unexpectedly calling the `validateFormData()` method during schema parsing');
3504
+ };
3505
+ return ParserValidator;
3506
+ }();
3507
+
3508
+ /** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
3509
+ * capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
3510
+ * `retrieveSchemaInternal()`, the `resolveAnyOrOneOfSchemas()` function is called. For each of the schemas returned
3511
+ * from THAT call have `properties`, then each of the sub-schema property objects are then recursively parsed.
3512
+ *
3513
+ * @param validator - The `ParserValidator` implementation used to capture `isValid()` calls during parsing
3514
+ * @param recurseList - The list of schemas returned from the `retrieveSchemaInternal`, preventing infinite recursion
3515
+ * @param rootSchema - The root schema from which the schema parsing began
3516
+ * @param schema - The current schema element being parsed
3517
+ */
3518
+ function parseSchema(validator, recurseList, rootSchema, schema) {
3519
+ var schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true);
3520
+ schemas.forEach(function (schema) {
3521
+ var sameSchemaIndex = recurseList.findIndex(function (item) {
3522
+ return isEqual__default["default"](item, schema);
3523
+ });
3524
+ if (sameSchemaIndex === -1) {
3525
+ recurseList.push(schema);
3526
+ var allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true);
3527
+ allOptions.forEach(function (s) {
3528
+ if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
3529
+ forEach__default["default"](schema[PROPERTIES_KEY], function (value) {
3530
+ parseSchema(validator, recurseList, rootSchema, value);
3531
+ });
3532
+ }
3533
+ });
3534
+ }
3535
+ });
3536
+ }
3537
+ /** Parses the given `rootSchema` to extract out all the sub-schemas that maybe contained within it. Returns a map of
3538
+ * the hash of the schema to schema/sub-schema.
3539
+ *
3540
+ * @param rootSchema - The root schema to parse for sub-schemas used by `isValid()` calls
3541
+ * @returns - The `SchemaMap` of all schemas that were parsed
3542
+ */
3543
+ function schemaParser(rootSchema) {
3544
+ var validator = new ParserValidator(rootSchema);
3545
+ var recurseList = [];
3546
+ parseSchema(validator, recurseList, rootSchema, rootSchema);
3547
+ return validator.getSchemaMap();
3548
+ }
3549
+
3111
3550
  exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
3112
3551
  exports.ADDITIONAL_PROPERTY_FLAG = ADDITIONAL_PROPERTY_FLAG;
3113
3552
  exports.ALL_OF_KEY = ALL_OF_KEY;
@@ -3120,6 +3559,7 @@ exports.ENUM_KEY = ENUM_KEY;
3120
3559
  exports.ERRORS_KEY = ERRORS_KEY;
3121
3560
  exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
3122
3561
  exports.ID_KEY = ID_KEY;
3562
+ exports.IF_KEY = IF_KEY;
3123
3563
  exports.ITEMS_KEY = ITEMS_KEY;
3124
3564
  exports.NAME_KEY = NAME_KEY;
3125
3565
  exports.ONE_OF_KEY = ONE_OF_KEY;
@@ -3153,6 +3593,7 @@ exports.examplesId = examplesId;
3153
3593
  exports.findSchemaDefinition = findSchemaDefinition;
3154
3594
  exports.getClosestMatchingOption = getClosestMatchingOption;
3155
3595
  exports.getDefaultFormState = getDefaultFormState;
3596
+ exports.getDiscriminatorFieldFromSchema = getDiscriminatorFieldFromSchema;
3156
3597
  exports.getDisplayLabel = getDisplayLabel;
3157
3598
  exports.getFirstMatchingOption = getFirstMatchingOption;
3158
3599
  exports.getInputProps = getInputProps;
@@ -3164,6 +3605,7 @@ exports.getUiOptions = getUiOptions;
3164
3605
  exports.getWidget = getWidget;
3165
3606
  exports.guessType = guessType;
3166
3607
  exports.hasWidget = hasWidget;
3608
+ exports.hashForSchema = hashForSchema;
3167
3609
  exports.helpId = helpId;
3168
3610
  exports.isConstant = isConstant;
3169
3611
  exports.isCustomWidget = isCustomWidget;
@@ -3187,6 +3629,7 @@ exports.rangeSpec = rangeSpec;
3187
3629
  exports.replaceStringParameters = replaceStringParameters;
3188
3630
  exports.retrieveSchema = retrieveSchema;
3189
3631
  exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
3632
+ exports.schemaParser = schemaParser;
3190
3633
  exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
3191
3634
  exports.shouldRender = shouldRender;
3192
3635
  exports.titleId = titleId;