@rjsf/utils 5.24.10 → 6.0.0-beta.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.
Files changed (182) hide show
  1. package/dist/index.js +605 -330
  2. package/dist/index.js.map +4 -4
  3. package/dist/utils.esm.js +575 -300
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +519 -268
  6. package/lib/ErrorSchemaBuilder.d.ts +7 -3
  7. package/lib/ErrorSchemaBuilder.js +1 -0
  8. package/lib/ErrorSchemaBuilder.js.map +1 -1
  9. package/lib/allowAdditionalItems.js.map +1 -1
  10. package/lib/asNumber.js.map +1 -1
  11. package/lib/canExpand.js +1 -1
  12. package/lib/canExpand.js.map +1 -1
  13. package/lib/constants.d.ts +11 -3
  14. package/lib/constants.js +11 -3
  15. package/lib/constants.js.map +1 -1
  16. package/lib/createErrorHandler.js.map +1 -1
  17. package/lib/createSchemaUtils.js +31 -27
  18. package/lib/createSchemaUtils.js.map +1 -1
  19. package/lib/dataURItoBlob.js.map +1 -1
  20. package/lib/dateRangeOptions.js.map +1 -1
  21. package/lib/deepEquals.js.map +1 -1
  22. package/lib/enumOptionsDeselectValue.js.map +1 -1
  23. package/lib/enumOptionsIndexForValue.js.map +1 -1
  24. package/lib/enumOptionsIsSelected.js.map +1 -1
  25. package/lib/enumOptionsSelectValue.js.map +1 -1
  26. package/lib/enumOptionsValueForIndex.js.map +1 -1
  27. package/lib/enums.d.ts +2 -0
  28. package/lib/enums.js +2 -0
  29. package/lib/enums.js.map +1 -1
  30. package/lib/findSchemaDefinition.js.map +1 -1
  31. package/lib/getChangedFields.js.map +1 -1
  32. package/lib/getDateElementProps.js.map +1 -1
  33. package/lib/getDiscriminatorFieldFromSchema.js +2 -1
  34. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  35. package/lib/getInputProps.js.map +1 -1
  36. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  37. package/lib/getSchemaType.d.ts +1 -0
  38. package/lib/getSchemaType.js +2 -1
  39. package/lib/getSchemaType.js.map +1 -1
  40. package/lib/getSubmitButtonOptions.js.map +1 -1
  41. package/lib/getTemplate.js +9 -0
  42. package/lib/getTemplate.js.map +1 -1
  43. package/lib/getTestIds.d.ts +17 -0
  44. package/lib/getTestIds.js +34 -0
  45. package/lib/getTestIds.js.map +1 -0
  46. package/lib/getUiOptions.js.map +1 -1
  47. package/lib/getWidget.js.map +1 -1
  48. package/lib/guessType.d.ts +1 -1
  49. package/lib/guessType.js.map +1 -1
  50. package/lib/hasWidget.js.map +1 -1
  51. package/lib/hashForSchema.d.ts +22 -0
  52. package/lib/hashForSchema.js +24 -6
  53. package/lib/hashForSchema.js.map +1 -1
  54. package/lib/idGenerators.d.ts +7 -0
  55. package/lib/idGenerators.js +9 -0
  56. package/lib/idGenerators.js.map +1 -1
  57. package/lib/index.d.ts +5 -3
  58. package/lib/index.js +5 -3
  59. package/lib/index.js.map +1 -1
  60. package/lib/isObject.d.ts +1 -1
  61. package/lib/isObject.js.map +1 -1
  62. package/lib/lookupFromFormContext.d.ts +11 -0
  63. package/lib/lookupFromFormContext.js +20 -0
  64. package/lib/lookupFromFormContext.js.map +1 -0
  65. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  66. package/lib/mergeObjects.js.map +1 -1
  67. package/lib/mergeSchemas.js.map +1 -1
  68. package/lib/optionsList.d.ts +8 -6
  69. package/lib/optionsList.js +29 -18
  70. package/lib/optionsList.js.map +1 -1
  71. package/lib/orderProperties.js.map +1 -1
  72. package/lib/pad.js.map +1 -1
  73. package/lib/parseDateString.js +1 -1
  74. package/lib/parseDateString.js.map +1 -1
  75. package/lib/parser/ParserValidator.js.map +1 -1
  76. package/lib/parser/schemaParser.js.map +1 -1
  77. package/lib/rangeSpec.js.map +1 -1
  78. package/lib/replaceStringParameters.js.map +1 -1
  79. package/lib/schema/findFieldInSchema.d.ts +19 -0
  80. package/lib/schema/findFieldInSchema.js +61 -0
  81. package/lib/schema/findFieldInSchema.js.map +1 -0
  82. package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
  83. package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
  84. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
  85. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  86. package/lib/schema/getDefaultFormState.js +2 -3
  87. package/lib/schema/getDefaultFormState.js.map +1 -1
  88. package/lib/schema/getDisplayLabel.js.map +1 -1
  89. package/lib/schema/getFirstMatchingOption.js +70 -2
  90. package/lib/schema/getFirstMatchingOption.js.map +1 -1
  91. package/lib/schema/getFromSchema.d.ts +14 -0
  92. package/lib/schema/getFromSchema.js +39 -0
  93. package/lib/schema/getFromSchema.js.map +1 -0
  94. package/lib/schema/index.d.ts +4 -3
  95. package/lib/schema/index.js +4 -3
  96. package/lib/schema/index.js.map +1 -1
  97. package/lib/schema/isFilesArray.js.map +1 -1
  98. package/lib/schema/isMultiSelect.js.map +1 -1
  99. package/lib/schema/isSelect.js.map +1 -1
  100. package/lib/schema/retrieveSchema.d.ts +7 -0
  101. package/lib/schema/retrieveSchema.js +65 -21
  102. package/lib/schema/retrieveSchema.js.map +1 -1
  103. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  104. package/lib/schema/toIdSchema.js +20 -19
  105. package/lib/schema/toIdSchema.js.map +1 -1
  106. package/lib/schema/toPathSchema.js +1 -1
  107. package/lib/schema/toPathSchema.js.map +1 -1
  108. package/lib/schemaRequiresTrueValue.js.map +1 -1
  109. package/lib/toConstant.js.map +1 -1
  110. package/lib/toErrorList.js.map +1 -1
  111. package/lib/toErrorSchema.js.map +1 -1
  112. package/lib/tsconfig.tsbuildinfo +1 -1
  113. package/lib/types.d.ts +127 -128
  114. package/lib/unwrapErrorHandler.js.map +1 -1
  115. package/lib/utcToLocal.js.map +1 -1
  116. package/lib/validationDataMerge.js.map +1 -1
  117. package/lib/withIdRefPrefix.js.map +1 -1
  118. package/package.json +35 -25
  119. package/src/ErrorSchemaBuilder.ts +10 -4
  120. package/src/canExpand.ts +2 -2
  121. package/src/constants.ts +12 -3
  122. package/src/createSchemaUtils.ts +79 -43
  123. package/src/dataURItoBlob.ts +1 -1
  124. package/src/dateRangeOptions.ts +1 -1
  125. package/src/enumOptionsDeselectValue.ts +1 -1
  126. package/src/enumOptionsIndexForValue.ts +1 -1
  127. package/src/enumOptionsIsSelected.ts +1 -1
  128. package/src/enumOptionsSelectValue.ts +1 -1
  129. package/src/enumOptionsValueForIndex.ts +1 -1
  130. package/src/enums.ts +2 -0
  131. package/src/findSchemaDefinition.ts +2 -2
  132. package/src/getDateElementProps.ts +2 -2
  133. package/src/getDiscriminatorFieldFromSchema.ts +2 -1
  134. package/src/getInputProps.ts +2 -2
  135. package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
  136. package/src/getSchemaType.ts +3 -2
  137. package/src/getSubmitButtonOptions.ts +1 -1
  138. package/src/getTemplate.ts +12 -1
  139. package/src/getTestIds.ts +40 -0
  140. package/src/getUiOptions.ts +2 -2
  141. package/src/getWidget.tsx +2 -2
  142. package/src/hasWidget.ts +1 -1
  143. package/src/hashForSchema.ts +26 -6
  144. package/src/idGenerators.ts +10 -0
  145. package/src/index.ts +19 -2
  146. package/src/isCustomWidget.ts +1 -1
  147. package/src/isObject.ts +1 -1
  148. package/src/labelValue.ts +2 -2
  149. package/src/lookupFromFormContext.ts +26 -0
  150. package/src/mergeDefaultsWithFormData.ts +3 -3
  151. package/src/mergeObjects.ts +24 -21
  152. package/src/optionsList.ts +31 -22
  153. package/src/parser/ParserValidator.ts +2 -2
  154. package/src/parser/schemaParser.ts +2 -2
  155. package/src/schema/findFieldInSchema.ts +138 -0
  156. package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
  157. package/src/schema/getClosestMatchingOption.ts +8 -8
  158. package/src/schema/getDefaultFormState.ts +26 -25
  159. package/src/schema/getDisplayLabel.ts +2 -2
  160. package/src/schema/getFirstMatchingOption.ts +79 -4
  161. package/src/schema/getFromSchema.ts +100 -0
  162. package/src/schema/index.ts +6 -4
  163. package/src/schema/isFilesArray.ts +2 -2
  164. package/src/schema/isMultiSelect.ts +2 -2
  165. package/src/schema/isSelect.ts +1 -1
  166. package/src/schema/retrieveSchema.ts +135 -69
  167. package/src/schema/sanitizeDataForNewSchema.ts +10 -10
  168. package/src/schema/toIdSchema.ts +45 -44
  169. package/src/schema/toPathSchema.ts +10 -10
  170. package/src/toErrorList.ts +2 -2
  171. package/src/types.ts +233 -173
  172. package/src/validationDataMerge.ts +1 -1
  173. package/src/withIdRefPrefix.ts +1 -1
  174. package/LICENSE.md +0 -201
  175. package/lib/schema/getMatchingOption.d.ts +0 -14
  176. package/lib/schema/getMatchingOption.js +0 -85
  177. package/lib/schema/getMatchingOption.js.map +0 -1
  178. package/lib/schema/mergeValidationData.d.ts +0 -14
  179. package/lib/schema/mergeValidationData.js +0 -28
  180. package/lib/schema/mergeValidationData.js.map +0 -1
  181. package/src/schema/getMatchingOption.ts +0 -103
  182. package/src/schema/mergeValidationData.ts +0 -38
@@ -16,6 +16,7 @@ import {
16
16
  IF_KEY,
17
17
  ITEMS_KEY,
18
18
  ONE_OF_KEY,
19
+ PATTERN_PROPERTIES_KEY,
19
20
  PROPERTIES_KEY,
20
21
  REF_KEY,
21
22
  } from '../constants';
@@ -34,6 +35,7 @@ import {
34
35
  } from '../types';
35
36
  import getFirstMatchingOption from './getFirstMatchingOption';
36
37
  import deepEquals from '../deepEquals';
38
+ import isEmpty from 'lodash/isEmpty';
37
39
 
38
40
  /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
39
41
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
@@ -49,13 +51,13 @@ import deepEquals from '../deepEquals';
49
51
  export default function retrieveSchema<
50
52
  T = any,
51
53
  S extends StrictRJSFSchema = RJSFSchema,
52
- F extends FormContextType = any
54
+ F extends FormContextType = any,
53
55
  >(
54
56
  validator: ValidatorType<T, S, F>,
55
57
  schema: S,
56
58
  rootSchema: S = {} as S,
57
59
  rawFormData?: T,
58
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
60
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
59
61
  ): S {
60
62
  return retrieveSchemaInternal<T, S, F>(
61
63
  validator,
@@ -64,7 +66,7 @@ export default function retrieveSchema<
64
66
  rawFormData,
65
67
  undefined,
66
68
  undefined,
67
- experimental_customMergeAllOf
69
+ experimental_customMergeAllOf,
68
70
  )[0];
69
71
  }
70
72
 
@@ -89,7 +91,7 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
89
91
  expandAllBranches: boolean,
90
92
  recurseList: string[],
91
93
  formData?: T,
92
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
94
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
93
95
  ): S[] {
94
96
  const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
95
97
 
@@ -106,8 +108,8 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
106
108
  formData,
107
109
  expandAllBranches,
108
110
  recurseList,
109
- experimental_customMergeAllOf
110
- )
111
+ experimental_customMergeAllOf,
112
+ ),
111
113
  );
112
114
  }
113
115
  if (otherwise && typeof otherwise !== 'boolean') {
@@ -119,8 +121,8 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
119
121
  formData,
120
122
  expandAllBranches,
121
123
  recurseList,
122
- experimental_customMergeAllOf
123
- )
124
+ experimental_customMergeAllOf,
125
+ ),
124
126
  );
125
127
  }
126
128
  } else {
@@ -134,8 +136,8 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
134
136
  formData,
135
137
  expandAllBranches,
136
138
  recurseList,
137
- experimental_customMergeAllOf
138
- )
139
+ experimental_customMergeAllOf,
140
+ ),
139
141
  );
140
142
  }
141
143
  }
@@ -150,8 +152,8 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
150
152
  formData,
151
153
  expandAllBranches,
152
154
  recurseList,
153
- experimental_customMergeAllOf
154
- )
155
+ experimental_customMergeAllOf,
156
+ ),
155
157
  );
156
158
  }
157
159
 
@@ -180,12 +182,34 @@ export function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchem
180
182
  permutations.forEach((permutation) => permutation.push(list[0]));
181
183
  return permutations;
182
184
  },
183
- [[]] as S[][] // Start with an empty list
185
+ [[]] as S[][], // Start with an empty list
184
186
  );
185
187
 
186
188
  return allPermutations;
187
189
  }
188
190
 
191
+ /** Returns the subset of 'patternProperties' specifications that match the given 'key'
192
+ *
193
+ * @param schema - The schema whose 'patternProperties' are to be filtered
194
+ * @param key - The key to match against the 'patternProperties' specifications
195
+ * @returns - The subset of 'patternProperties' specifications that match the given 'key'
196
+ */
197
+ export function getMatchingPatternProperties<S extends StrictRJSFSchema = RJSFSchema>(
198
+ schema: S,
199
+ key: string,
200
+ ): Required<S['patternProperties']> {
201
+ return Object.keys(schema.patternProperties!)
202
+ .filter((pattern: string) => RegExp(pattern).test(key))
203
+ .reduce(
204
+ (obj, pattern) => {
205
+ // Pass the pattern using the `[]` index notation so that any `.` in the pattern are not used as a dotted path
206
+ set(obj, [pattern], schema.patternProperties![pattern]);
207
+ return obj;
208
+ },
209
+ {} as Required<S['patternProperties']>,
210
+ );
211
+ }
212
+
189
213
  /** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
190
214
  * down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
191
215
  * `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
@@ -207,7 +231,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
207
231
  expandAllBranches: boolean,
208
232
  recurseList: string[],
209
233
  formData?: T,
210
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
234
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
211
235
  ): S[] {
212
236
  const updatedSchemas = resolveReference<T, S, F>(
213
237
  validator,
@@ -215,7 +239,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
215
239
  rootSchema,
216
240
  expandAllBranches,
217
241
  recurseList,
218
- formData
242
+ formData,
219
243
  );
220
244
  if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
221
245
  // return the updatedSchemas array if it has either multiple schemas within it
@@ -229,7 +253,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
229
253
  rootSchema,
230
254
  expandAllBranches,
231
255
  recurseList,
232
- formData
256
+ formData,
233
257
  );
234
258
  return resolvedSchemas.flatMap((s) => {
235
259
  return retrieveSchemaInternal<T, S, F>(
@@ -239,7 +263,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
239
263
  formData,
240
264
  expandAllBranches,
241
265
  recurseList,
242
- experimental_customMergeAllOf
266
+ experimental_customMergeAllOf,
243
267
  );
244
268
  });
245
269
  }
@@ -252,8 +276,8 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
252
276
  formData,
253
277
  expandAllBranches,
254
278
  recurseList,
255
- experimental_customMergeAllOf
256
- )
279
+ experimental_customMergeAllOf,
280
+ ),
257
281
  );
258
282
  const allPermutations = getAllPermutationsOfXxxOf<S>(allOfSchemaElements);
259
283
  return allPermutations.map((permutation) => ({
@@ -286,7 +310,7 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
286
310
  expandAllBranches: boolean,
287
311
  recurseList: string[],
288
312
  formData?: T,
289
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
313
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
290
314
  ): S[] {
291
315
  const updatedSchema = resolveAllReferences<S>(schema, rootSchema, recurseList);
292
316
  if (updatedSchema !== schema) {
@@ -298,7 +322,7 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
298
322
  formData,
299
323
  expandAllBranches,
300
324
  recurseList,
301
- experimental_customMergeAllOf
325
+ experimental_customMergeAllOf,
302
326
  );
303
327
  }
304
328
  return [schema];
@@ -314,7 +338,7 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
314
338
  export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
315
339
  schema: S,
316
340
  rootSchema: S,
317
- recurseList: string[]
341
+ recurseList: string[],
318
342
  ): S {
319
343
  if (!isObject(schema)) {
320
344
  return schema;
@@ -342,7 +366,7 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
342
366
  result[key] = resolveAllReferences(value as S, rootSchema, childList);
343
367
  childrenLists.push(childList);
344
368
  },
345
- {} as RJSFSchema
369
+ {} as RJSFSchema,
346
370
  );
347
371
  merge(recurseList, uniq(flattenDeep(childrenLists)));
348
372
  resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
@@ -374,13 +398,13 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
374
398
  export function stubExistingAdditionalProperties<
375
399
  T = any,
376
400
  S extends StrictRJSFSchema = RJSFSchema,
377
- F extends FormContextType = any
401
+ F extends FormContextType = any,
378
402
  >(
379
403
  validator: ValidatorType<T, S, F>,
380
404
  theSchema: S,
381
405
  rootSchema?: S,
382
406
  aFormData?: T,
383
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
407
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
384
408
  ): S {
385
409
  // Clone the schema so that we don't ruin the consumer's original
386
410
  const schema = {
@@ -395,35 +419,55 @@ export function stubExistingAdditionalProperties<
395
419
  // No need to stub, our schema already has the property
396
420
  return;
397
421
  }
398
-
399
- let additionalProperties: S['additionalProperties'] = {};
400
- if (typeof schema.additionalProperties !== 'boolean') {
401
- if (REF_KEY in schema.additionalProperties!) {
402
- additionalProperties = retrieveSchema<T, S, F>(
422
+ if (PATTERN_PROPERTIES_KEY in schema) {
423
+ const matchingProperties = getMatchingPatternProperties(schema, key);
424
+ if (!isEmpty(matchingProperties)) {
425
+ schema.properties[key] = retrieveSchema<T, S, F>(
403
426
  validator,
404
- { $ref: get(schema.additionalProperties, [REF_KEY]) } as S,
427
+ { allOf: Object.values(matchingProperties) } as S,
405
428
  rootSchema,
406
429
  formData as T,
407
- experimental_customMergeAllOf
430
+ experimental_customMergeAllOf,
408
431
  );
409
- } else if ('type' in schema.additionalProperties!) {
410
- additionalProperties = { ...schema.additionalProperties };
411
- } else if (ANY_OF_KEY in schema.additionalProperties! || ONE_OF_KEY in schema.additionalProperties!) {
412
- additionalProperties = {
413
- type: 'object',
414
- ...schema.additionalProperties,
415
- };
432
+ set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
433
+ return;
434
+ }
435
+ }
436
+ if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
437
+ let additionalProperties: S['additionalProperties'] = {};
438
+ if (typeof schema.additionalProperties !== 'boolean') {
439
+ if (REF_KEY in schema.additionalProperties!) {
440
+ additionalProperties = retrieveSchema<T, S, F>(
441
+ validator,
442
+ { $ref: get(schema.additionalProperties, [REF_KEY]) } as S,
443
+ rootSchema,
444
+ formData as T,
445
+ experimental_customMergeAllOf,
446
+ );
447
+ } else if ('type' in schema.additionalProperties!) {
448
+ additionalProperties = { ...schema.additionalProperties };
449
+ } else if (ANY_OF_KEY in schema.additionalProperties! || ONE_OF_KEY in schema.additionalProperties!) {
450
+ additionalProperties = {
451
+ type: 'object',
452
+ ...schema.additionalProperties,
453
+ };
454
+ } else {
455
+ additionalProperties = { type: guessType(get(formData, [key])) };
456
+ }
416
457
  } else {
417
458
  additionalProperties = { type: guessType(get(formData, [key])) };
418
459
  }
460
+
461
+ // The type of our new key should match the additionalProperties value;
462
+ schema.properties[key] = additionalProperties;
463
+ // Set our additional property flag so we know it was dynamically added
464
+ set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
419
465
  } else {
420
- additionalProperties = { type: guessType(get(formData, [key])) };
466
+ // Invalid property
467
+ schema.properties[key] = { type: 'null' };
468
+ // Set our additional property flag so we know it was dynamically added
469
+ set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
421
470
  }
422
-
423
- // The type of our new key should match the additionalProperties value;
424
- schema.properties[key] = additionalProperties;
425
- // Set our additional property flag so we know it was dynamically added
426
- set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
427
471
  });
428
472
 
429
473
  return schema;
@@ -448,7 +492,7 @@ export function stubExistingAdditionalProperties<
448
492
  export function retrieveSchemaInternal<
449
493
  T = any,
450
494
  S extends StrictRJSFSchema = RJSFSchema,
451
- F extends FormContextType = any
495
+ F extends FormContextType = any,
452
496
  >(
453
497
  validator: ValidatorType<T, S, F>,
454
498
  schema: S,
@@ -456,7 +500,7 @@ export function retrieveSchemaInternal<
456
500
  rawFormData?: T,
457
501
  expandAllBranches = false,
458
502
  recurseList: string[] = [],
459
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
503
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
460
504
  ): S[] {
461
505
  if (!isObject(schema)) {
462
506
  return [{} as S];
@@ -468,7 +512,7 @@ export function retrieveSchemaInternal<
468
512
  expandAllBranches,
469
513
  recurseList,
470
514
  rawFormData,
471
- experimental_customMergeAllOf
515
+ experimental_customMergeAllOf,
472
516
  );
473
517
  return resolvedSchemas.flatMap((s: S) => {
474
518
  let resolvedSchema = s;
@@ -480,7 +524,7 @@ export function retrieveSchemaInternal<
480
524
  expandAllBranches,
481
525
  recurseList,
482
526
  rawFormData as T,
483
- experimental_customMergeAllOf
527
+ experimental_customMergeAllOf,
484
528
  );
485
529
  }
486
530
  if (ALL_OF_KEY in resolvedSchema) {
@@ -516,15 +560,37 @@ export function retrieveSchemaInternal<
516
560
  return resolvedSchemaWithoutAllOf as S;
517
561
  }
518
562
  }
563
+ if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
564
+ resolvedSchema = Object.keys(resolvedSchema.properties!).reduce(
565
+ (schema, key) => {
566
+ const matchingProperties = getMatchingPatternProperties(schema, key);
567
+ if (!isEmpty(matchingProperties)) {
568
+ schema.properties[key] = retrieveSchema<T, S, F>(
569
+ validator,
570
+ { allOf: [schema.properties[key], ...Object.values(matchingProperties)] } as S,
571
+ rootSchema,
572
+ rawFormData as T,
573
+ experimental_customMergeAllOf,
574
+ );
575
+ }
576
+ return schema;
577
+ },
578
+ {
579
+ ...resolvedSchema,
580
+ properties: { ...resolvedSchema.properties },
581
+ },
582
+ );
583
+ }
519
584
  const hasAdditionalProperties =
520
- ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
585
+ PATTERN_PROPERTIES_KEY in resolvedSchema ||
586
+ (ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false);
521
587
  if (hasAdditionalProperties) {
522
588
  return stubExistingAdditionalProperties<T, S, F>(
523
589
  validator,
524
590
  resolvedSchema,
525
591
  rootSchema,
526
592
  rawFormData as T,
527
- experimental_customMergeAllOf
593
+ experimental_customMergeAllOf,
528
594
  );
529
595
  }
530
596
 
@@ -547,7 +613,7 @@ export function retrieveSchemaInternal<
547
613
  export function resolveAnyOrOneOfSchemas<
548
614
  T = any,
549
615
  S extends StrictRJSFSchema = RJSFSchema,
550
- F extends FormContextType = any
616
+ F extends FormContextType = any,
551
617
  >(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, rawFormData?: T) {
552
618
  let anyOrOneOf: S[] | undefined;
553
619
  const { oneOf, anyOf, ...remaining } = schema;
@@ -595,7 +661,7 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
595
661
  expandAllBranches: boolean,
596
662
  recurseList: string[],
597
663
  formData?: T,
598
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
664
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
599
665
  ): S[] {
600
666
  // Drop the dependencies from the source schema.
601
667
  const { dependencies, ...remainingSchema } = schema;
@@ -604,7 +670,7 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
604
670
  remainingSchema as S,
605
671
  rootSchema,
606
672
  expandAllBranches,
607
- formData
673
+ formData,
608
674
  );
609
675
  return resolvedSchemas.flatMap((resolvedSchema) =>
610
676
  processDependencies<T, S, F>(
@@ -615,8 +681,8 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
615
681
  expandAllBranches,
616
682
  recurseList,
617
683
  formData,
618
- experimental_customMergeAllOf
619
- )
684
+ experimental_customMergeAllOf,
685
+ ),
620
686
  );
621
687
  }
622
688
 
@@ -642,7 +708,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
642
708
  expandAllBranches: boolean,
643
709
  recurseList: string[],
644
710
  formData?: T,
645
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
711
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
646
712
  ): S[] {
647
713
  let schemas = [resolvedSchema];
648
714
  // Process dependencies updating the local schema properties as appropriate.
@@ -657,7 +723,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
657
723
  }
658
724
  const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
659
725
  dependencyKey,
660
- dependencies as GenericObjectType
726
+ dependencies as GenericObjectType,
661
727
  );
662
728
  if (Array.isArray(dependencyValue)) {
663
729
  schemas[0] = withDependentProperties<S>(resolvedSchema, dependencyValue);
@@ -671,7 +737,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
671
737
  expandAllBranches,
672
738
  recurseList,
673
739
  formData,
674
- experimental_customMergeAllOf
740
+ experimental_customMergeAllOf,
675
741
  );
676
742
  }
677
743
  return schemas.flatMap((schema) =>
@@ -683,8 +749,8 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
683
749
  expandAllBranches,
684
750
  recurseList,
685
751
  formData,
686
- experimental_customMergeAllOf
687
- )
752
+ experimental_customMergeAllOf,
753
+ ),
688
754
  );
689
755
  }
690
756
  return schemas;
@@ -698,7 +764,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
698
764
  */
699
765
  export function withDependentProperties<S extends StrictRJSFSchema = RJSFSchema>(
700
766
  schema: S,
701
- additionallyRequired?: string[]
767
+ additionallyRequired?: string[],
702
768
  ) {
703
769
  if (!additionallyRequired) {
704
770
  return schema;
@@ -733,7 +799,7 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
733
799
  expandAllBranches: boolean,
734
800
  recurseList: string[],
735
801
  formData?: T,
736
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
802
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
737
803
  ): S[] {
738
804
  const dependentSchemas = retrieveSchemaInternal<T, S, F>(
739
805
  validator,
@@ -742,7 +808,7 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
742
808
  formData,
743
809
  expandAllBranches,
744
810
  recurseList,
745
- experimental_customMergeAllOf
811
+ experimental_customMergeAllOf,
746
812
  );
747
813
  return dependentSchemas.flatMap((dependent) => {
748
814
  const { oneOf, ...dependentSchema } = dependent;
@@ -769,8 +835,8 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
769
835
  expandAllBranches,
770
836
  recurseList,
771
837
  formData,
772
- experimental_customMergeAllOf
773
- )
838
+ experimental_customMergeAllOf,
839
+ ),
774
840
  );
775
841
  });
776
842
  }
@@ -794,7 +860,7 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
794
860
  export function withExactlyOneSubschema<
795
861
  T = any,
796
862
  S extends StrictRJSFSchema = RJSFSchema,
797
- F extends FormContextType = any
863
+ F extends FormContextType = any,
798
864
  >(
799
865
  validator: ValidatorType<T, S, F>,
800
866
  schema: S,
@@ -804,7 +870,7 @@ export function withExactlyOneSubschema<
804
870
  expandAllBranches: boolean,
805
871
  recurseList: string[],
806
872
  formData?: T,
807
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
873
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
808
874
  ): S[] {
809
875
  const validSubschemas = oneOf!.filter((subschema) => {
810
876
  if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
@@ -838,7 +904,7 @@ export function withExactlyOneSubschema<
838
904
  formData,
839
905
  expandAllBranches,
840
906
  recurseList,
841
- experimental_customMergeAllOf
907
+ experimental_customMergeAllOf,
842
908
  );
843
909
  return schemas.map((s) => mergeSchemas(schema, s) as S);
844
910
  });
@@ -65,14 +65,14 @@ const NO_VALUE = Symbol('no Value');
65
65
  export default function sanitizeDataForNewSchema<
66
66
  T = any,
67
67
  S extends StrictRJSFSchema = RJSFSchema,
68
- F extends FormContextType = any
68
+ F extends FormContextType = any,
69
69
  >(
70
70
  validator: ValidatorType<T, S, F>,
71
71
  rootSchema: S,
72
72
  newSchema?: S,
73
73
  oldSchema?: S,
74
74
  data: any = {},
75
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
75
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
76
76
  ): T {
77
77
  // By default, we will clear the form data
78
78
  let newFormData;
@@ -93,8 +93,8 @@ export default function sanitizeDataForNewSchema<
93
93
  const nestedData: GenericObjectType = {};
94
94
  keys.forEach((key) => {
95
95
  const formValue = get(data, key);
96
- let oldKeyedSchema: S = get(oldSchema, [PROPERTIES_KEY, key], {});
97
- let newKeyedSchema: S = get(newSchema, [PROPERTIES_KEY, key], {});
96
+ let oldKeyedSchema: S = get(oldSchema, [PROPERTIES_KEY, key], {}) as S;
97
+ let newKeyedSchema: S = get(newSchema, [PROPERTIES_KEY, key], {}) as S;
98
98
  // Resolve the refs if they exist
99
99
  if (has(oldKeyedSchema, REF_KEY)) {
100
100
  oldKeyedSchema = retrieveSchema<T, S, F>(
@@ -102,7 +102,7 @@ export default function sanitizeDataForNewSchema<
102
102
  oldKeyedSchema,
103
103
  rootSchema,
104
104
  formValue,
105
- experimental_customMergeAllOf
105
+ experimental_customMergeAllOf,
106
106
  );
107
107
  }
108
108
  if (has(newKeyedSchema, REF_KEY)) {
@@ -111,7 +111,7 @@ export default function sanitizeDataForNewSchema<
111
111
  newKeyedSchema,
112
112
  rootSchema,
113
113
  formValue,
114
- experimental_customMergeAllOf
114
+ experimental_customMergeAllOf,
115
115
  );
116
116
  }
117
117
  // Now get types and see if they are the same
@@ -132,7 +132,7 @@ export default function sanitizeDataForNewSchema<
132
132
  newKeyedSchema,
133
133
  oldKeyedSchema,
134
134
  formValue,
135
- experimental_customMergeAllOf
135
+ experimental_customMergeAllOf,
136
136
  );
137
137
  if (itemData !== undefined || newSchemaTypeForKey === 'array') {
138
138
  // only put undefined values for the array type and not the object type
@@ -187,7 +187,7 @@ export default function sanitizeDataForNewSchema<
187
187
  oldSchemaItems as S,
188
188
  rootSchema,
189
189
  data as T,
190
- experimental_customMergeAllOf
190
+ experimental_customMergeAllOf,
191
191
  );
192
192
  }
193
193
  if (has(newSchemaItems, REF_KEY)) {
@@ -196,7 +196,7 @@ export default function sanitizeDataForNewSchema<
196
196
  newSchemaItems as S,
197
197
  rootSchema,
198
198
  data as T,
199
- experimental_customMergeAllOf
199
+ experimental_customMergeAllOf,
200
200
  );
201
201
  }
202
202
  // Now get types and see if they are the same
@@ -213,7 +213,7 @@ export default function sanitizeDataForNewSchema<
213
213
  newSchemaItems as S,
214
214
  oldSchemaItems as S,
215
215
  aValue,
216
- experimental_customMergeAllOf
216
+ experimental_customMergeAllOf,
217
217
  );
218
218
  if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
219
219
  newValue.push(itemValue);