@rjsf/utils 6.6.1 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/dist/index.cjs +534 -376
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +534 -376
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +561 -400
- package/lib/ErrorSchemaBuilder.d.ts +1 -1
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -0
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js +2 -0
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/constIsAjvDataReference.d.ts +1 -1
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -6
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +1 -1
- package/lib/createSchemaUtils.js +3 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js +3 -3
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +8 -7
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/enumOptionSelectedValue.d.ts +1 -1
- package/lib/enumOptionValueDecoder.d.ts +1 -1
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +15 -15
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +4 -6
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +3 -3
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +1 -1
- package/lib/getSchemaType.d.ts +1 -1
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -1
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +4 -4
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.js +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hashForSchema.d.ts +3 -1
- package/lib/hashForSchema.js +11 -4
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +1 -1
- package/lib/index.d.ts +14 -7
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +3 -3
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.d.ts +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/labelValue.d.ts +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/lookupFromFormContext.d.ts +1 -1
- package/lib/mergeDefaultsWithFormData.js +6 -5
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +4 -2
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +4 -2
- package/lib/mergeSchemas.js +13 -6
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +1 -1
- package/lib/optionsList.d.ts +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js +3 -3
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +2 -4
- package/lib/parser/ParserValidator.js +2 -0
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +7 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +1 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +1 -1
- package/lib/removeOptionalEmptyObjects.js +6 -8
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +1 -1
- package/lib/resolveUiSchema.js +16 -16
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -9
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +81 -43
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +2 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +1 -1
- package/lib/schema/index.js +9 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +1 -1
- package/lib/schema/isMultiSelect.d.ts +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +1 -1
- package/lib/schema/isSelect.js +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +1 -1
- package/lib/schema/omitExtraData.js +66 -52
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -3
- package/lib/schema/retrieveSchema.js +83 -56
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js +48 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +1 -1
- package/lib/schema/toPathSchema.js +9 -5
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.js +2 -2
- package/lib/shallowEquals.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +3 -3
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toFieldPathId.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +63 -57
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +7 -9
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +6 -6
- package/lib/useAltDateWidgetProps.js +3 -3
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +2 -2
- package/lib/useFileWidgetProps.js +3 -3
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +12 -12
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +19 -19
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/allowAdditionalItems.ts +2 -1
- package/src/asNumber.ts +2 -0
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +2 -2
- package/src/constants.ts +10 -7
- package/src/createErrorHandler.ts +6 -7
- package/src/createSchemaUtils.ts +4 -2
- package/src/dataURItoBlob.ts +3 -3
- package/src/dateRangeOptions.ts +9 -7
- package/src/englishStringTranslator.ts +1 -1
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +4 -0
- package/src/findSchemaDefinition.ts +18 -17
- package/src/getChangedFields.ts +5 -5
- package/src/getDateElementProps.ts +3 -3
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +1 -1
- package/src/getUiOptions.ts +10 -2
- package/src/getWidget.tsx +5 -6
- package/src/guessType.ts +1 -1
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +12 -5
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +16 -5
- package/src/isConstant.ts +1 -1
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +4 -4
- package/src/isRootSchema.ts +3 -5
- package/src/labelValue.ts +1 -1
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/lookupFromFormContext.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +8 -7
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +14 -7
- package/src/nameGenerators.ts +1 -1
- package/src/optionsList.ts +21 -23
- package/src/orderProperties.ts +4 -4
- package/src/pad.ts +1 -1
- package/src/parseDateString.ts +2 -2
- package/src/parser/ParserValidator.ts +4 -4
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +10 -9
- package/src/rangeSpec.ts +1 -2
- package/src/removeOptionalEmptyObjects.ts +8 -11
- package/src/resolveUiSchema.ts +32 -25
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
- package/src/schema/getClosestMatchingOption.ts +17 -11
- package/src/schema/getDefaultFormState.ts +104 -43
- package/src/schema/getDisplayLabel.ts +4 -5
- package/src/schema/getFirstMatchingOption.ts +3 -3
- package/src/schema/getFromSchema.ts +1 -1
- package/src/schema/index.ts +3 -0
- package/src/schema/isFilesArray.ts +1 -1
- package/src/schema/isMultiSelect.ts +7 -1
- package/src/schema/isSelect.ts +8 -2
- package/src/schema/omitExtraData.ts +73 -60
- package/src/schema/retrieveSchema.ts +131 -83
- package/src/schema/sanitizeDataForNewSchema.ts +57 -8
- package/src/schema/toPathSchema.ts +11 -7
- package/src/schemaRequiresTrueValue.ts +4 -4
- package/src/shallowEquals.ts +2 -2
- package/src/shouldRenderOptionalField.ts +1 -1
- package/src/toConstant.ts +1 -1
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +4 -4
- package/src/toErrorSchema.ts +1 -1
- package/src/toFieldPathId.ts +1 -1
- package/src/types.ts +92 -63
- package/src/unwrapErrorHandler.ts +11 -12
- package/src/useAltDateWidgetProps.tsx +10 -8
- package/src/useFileWidgetProps.ts +7 -7
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +12 -12
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
PATTERN_PROPERTIES_KEY,
|
|
21
21
|
PROPERTIES_KEY,
|
|
22
22
|
REF_KEY,
|
|
23
|
+
RJSF_REF_CYCLE_KEY,
|
|
23
24
|
RJSF_REF_KEY,
|
|
24
25
|
} from '../constants';
|
|
25
26
|
import deepEquals from '../deepEquals';
|
|
@@ -28,10 +29,11 @@ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema'
|
|
|
28
29
|
import guessType from '../guessType';
|
|
29
30
|
import isObject from '../isObject';
|
|
30
31
|
import mergeSchemas from '../mergeSchemas';
|
|
31
|
-
import {
|
|
32
|
+
import type {
|
|
32
33
|
Experimental_CustomMergeAllOf,
|
|
33
34
|
FormContextType,
|
|
34
35
|
GenericObjectType,
|
|
36
|
+
RJSFMarkedSchema,
|
|
35
37
|
RJSFSchema,
|
|
36
38
|
StrictRJSFSchema,
|
|
37
39
|
ValidatorType,
|
|
@@ -75,6 +77,18 @@ export default function retrieveSchema<
|
|
|
75
77
|
)[0];
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
/** Converts boolean schemas to equivalent object schemas for APIs that operate on `StrictRJSFSchema` objects.
|
|
81
|
+
*
|
|
82
|
+
* @param schema - The schema or boolean schema to normalize
|
|
83
|
+
* @returns - The original schema or an equivalent object schema
|
|
84
|
+
*/
|
|
85
|
+
function normalizeBooleanSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S | boolean): S {
|
|
86
|
+
if (typeof schema !== 'boolean') {
|
|
87
|
+
return schema;
|
|
88
|
+
}
|
|
89
|
+
return (schema ? {} : { not: {} }) as S;
|
|
90
|
+
}
|
|
91
|
+
|
|
78
92
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
79
93
|
* with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
|
|
80
94
|
* conditions will be returned.
|
|
@@ -105,10 +119,11 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
105
119
|
let schemas: S[] = [];
|
|
106
120
|
if (expandAllBranches) {
|
|
107
121
|
if (then && typeof then !== 'boolean') {
|
|
122
|
+
const thenSchema = then as unknown as S;
|
|
108
123
|
schemas = schemas.concat(
|
|
109
124
|
retrieveSchemaInternal<T, S, F>(
|
|
110
125
|
validator,
|
|
111
|
-
|
|
126
|
+
thenSchema,
|
|
112
127
|
rootSchema,
|
|
113
128
|
formData,
|
|
114
129
|
expandAllBranches,
|
|
@@ -118,10 +133,11 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
118
133
|
);
|
|
119
134
|
}
|
|
120
135
|
if (otherwise && typeof otherwise !== 'boolean') {
|
|
136
|
+
const otherwiseSchema = otherwise as unknown as S;
|
|
121
137
|
schemas = schemas.concat(
|
|
122
138
|
retrieveSchemaInternal<T, S, F>(
|
|
123
139
|
validator,
|
|
124
|
-
|
|
140
|
+
otherwiseSchema,
|
|
125
141
|
rootSchema,
|
|
126
142
|
formData,
|
|
127
143
|
expandAllBranches,
|
|
@@ -131,12 +147,13 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
131
147
|
);
|
|
132
148
|
}
|
|
133
149
|
} else {
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
150
|
+
const conditionalBranch = (conditionValue ? then : otherwise) as S | boolean | undefined;
|
|
151
|
+
if (conditionalBranch !== undefined) {
|
|
152
|
+
const conditionalSchema = normalizeBooleanSchema<S>(conditionalBranch);
|
|
136
153
|
schemas = schemas.concat(
|
|
137
154
|
retrieveSchemaInternal<T, S, F>(
|
|
138
155
|
validator,
|
|
139
|
-
conditionalSchema
|
|
156
|
+
conditionalSchema,
|
|
140
157
|
rootSchema,
|
|
141
158
|
formData,
|
|
142
159
|
expandAllBranches,
|
|
@@ -187,7 +204,7 @@ export function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchem
|
|
|
187
204
|
permutations.forEach((permutation) => permutation.push(list[0]));
|
|
188
205
|
return permutations;
|
|
189
206
|
},
|
|
190
|
-
[[]]
|
|
207
|
+
[[]], // Start with an empty list
|
|
191
208
|
);
|
|
192
209
|
|
|
193
210
|
return allPermutations;
|
|
@@ -265,8 +282,8 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
265
282
|
formData,
|
|
266
283
|
experimental_customMergeAllOf,
|
|
267
284
|
);
|
|
268
|
-
return resolvedSchemas.flatMap((s) =>
|
|
269
|
-
|
|
285
|
+
return resolvedSchemas.flatMap((s) =>
|
|
286
|
+
retrieveSchemaInternal<T, S, F>(
|
|
270
287
|
validator,
|
|
271
288
|
s,
|
|
272
289
|
rootSchema,
|
|
@@ -274,8 +291,8 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
274
291
|
expandAllBranches,
|
|
275
292
|
recurseList,
|
|
276
293
|
experimental_customMergeAllOf,
|
|
277
|
-
)
|
|
278
|
-
|
|
294
|
+
),
|
|
295
|
+
);
|
|
279
296
|
}
|
|
280
297
|
if (ALL_OF_KEY in schema && Array.isArray(schema[ALL_OF_KEY])) {
|
|
281
298
|
const allOfSchemaElements: S[][] = schema.allOf.map((allOfSubschema) =>
|
|
@@ -348,6 +365,10 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
348
365
|
* @param recurseList - List of $refs already resolved to prevent recursion
|
|
349
366
|
* @param [baseURI] - The base URI to be used for resolving relative references
|
|
350
367
|
* @param [resolveAnyOfOrOneOfRefs] - Optional flag indicating whether to resolved refs in anyOf/oneOf lists
|
|
368
|
+
* @param [markCycleOnDetection=false] - When true and a recursive $ref is detected, the returned schema is tagged
|
|
369
|
+
* with `__rjsf_ref_cycle: true` so that `SchemaField` can render a cycle indicator instead of recursing.
|
|
370
|
+
* Should only be `true` when called from an **object-property** context, because object properties are always
|
|
371
|
+
* rendered (creating an infinite loop), whereas array items and anyOf/oneOf branches are data-driven.
|
|
351
372
|
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved
|
|
352
373
|
*/
|
|
353
374
|
export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
@@ -356,24 +377,26 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
356
377
|
recurseList: string[],
|
|
357
378
|
baseURI?: string,
|
|
358
379
|
resolveAnyOfOrOneOfRefs?: boolean,
|
|
380
|
+
markCycleOnDetection = false,
|
|
359
381
|
): S {
|
|
360
382
|
if (!isObject(schema)) {
|
|
361
383
|
return schema;
|
|
362
384
|
}
|
|
363
385
|
let resolvedSchema: S = schema;
|
|
386
|
+
let currentBaseURI = baseURI;
|
|
364
387
|
// resolve top level ref
|
|
365
388
|
if (REF_KEY in resolvedSchema) {
|
|
366
389
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
367
390
|
// Check for a recursive reference and stop the loop
|
|
368
391
|
if (recurseList.includes($ref!)) {
|
|
369
|
-
return resolvedSchema;
|
|
392
|
+
return markCycleOnDetection ? ({ ...resolvedSchema, [RJSF_REF_CYCLE_KEY]: true } as S) : resolvedSchema;
|
|
370
393
|
}
|
|
371
394
|
recurseList.push($ref!);
|
|
372
395
|
// Retrieve the referenced schema definition.
|
|
373
|
-
const refSchema = findSchemaDefinition<S>($ref, rootSchema,
|
|
396
|
+
const refSchema = findSchemaDefinition<S>($ref, rootSchema, currentBaseURI);
|
|
374
397
|
resolvedSchema = { ...refSchema, ...localSchema, [RJSF_REF_KEY]: $ref };
|
|
375
398
|
if (ID_KEY in resolvedSchema) {
|
|
376
|
-
|
|
399
|
+
currentBaseURI = resolvedSchema[ID_KEY];
|
|
377
400
|
}
|
|
378
401
|
}
|
|
379
402
|
|
|
@@ -381,9 +404,20 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
381
404
|
const childrenLists: string[][] = [];
|
|
382
405
|
const updatedProps = transform(
|
|
383
406
|
resolvedSchema[PROPERTIES_KEY]!,
|
|
384
|
-
(
|
|
407
|
+
(acc, value, key: string) => {
|
|
385
408
|
const childList: string[] = [...recurseList];
|
|
386
|
-
|
|
409
|
+
// Mark cycles only when NOT in resolveAnyOfOrOneOfRefs mode. When resolveAnyOfOrOneOfRefs=true
|
|
410
|
+
// (e.g. from ObjectField), options are resolved against a shared recurseList that accumulates
|
|
411
|
+
// refs across branches, causing false positives. In simple (non-anyOf) resolution, a $ref cycle
|
|
412
|
+
// in an object property always causes an infinite render loop and must be caught.
|
|
413
|
+
acc[key] = resolveAllReferences(
|
|
414
|
+
value as S,
|
|
415
|
+
rootSchema,
|
|
416
|
+
childList,
|
|
417
|
+
currentBaseURI,
|
|
418
|
+
resolveAnyOfOrOneOfRefs,
|
|
419
|
+
!resolveAnyOfOrOneOfRefs,
|
|
420
|
+
);
|
|
387
421
|
childrenLists.push(childList);
|
|
388
422
|
},
|
|
389
423
|
{} as RJSFSchema,
|
|
@@ -399,7 +433,14 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
399
433
|
) {
|
|
400
434
|
resolvedSchema = {
|
|
401
435
|
...resolvedSchema,
|
|
402
|
-
|
|
436
|
+
// Array items are only rendered when data exists, so a $ref cycle here does NOT cause an infinite render.
|
|
437
|
+
items: resolveAllReferences(
|
|
438
|
+
resolvedSchema.items as S,
|
|
439
|
+
rootSchema,
|
|
440
|
+
recurseList,
|
|
441
|
+
currentBaseURI,
|
|
442
|
+
resolveAnyOfOrOneOfRefs,
|
|
443
|
+
),
|
|
403
444
|
};
|
|
404
445
|
}
|
|
405
446
|
|
|
@@ -417,7 +458,7 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
417
458
|
resolvedSchema = {
|
|
418
459
|
...resolvedSchema,
|
|
419
460
|
[key]: schemas.map((s: S) =>
|
|
420
|
-
resolveAllReferences(s, rootSchema, recurseList,
|
|
461
|
+
resolveAllReferences(s, rootSchema, recurseList, currentBaseURI, resolveAnyOfOrOneOfRefs),
|
|
421
462
|
),
|
|
422
463
|
};
|
|
423
464
|
}
|
|
@@ -469,7 +510,7 @@ export function stubExistingAdditionalProperties<
|
|
|
469
510
|
get(formData, [key]) as T,
|
|
470
511
|
experimental_customMergeAllOf,
|
|
471
512
|
);
|
|
472
|
-
|
|
513
|
+
(schema.properties[key] as RJSFMarkedSchema)[ADDITIONAL_PROPERTY_FLAG] = true;
|
|
473
514
|
return;
|
|
474
515
|
}
|
|
475
516
|
}
|
|
@@ -481,7 +522,7 @@ export function stubExistingAdditionalProperties<
|
|
|
481
522
|
validator,
|
|
482
523
|
{ [REF_KEY]: get(schema.additionalProperties, [REF_KEY]) } as S,
|
|
483
524
|
rootSchema,
|
|
484
|
-
formData as T,
|
|
525
|
+
get(formData, [key]) as T,
|
|
485
526
|
experimental_customMergeAllOf,
|
|
486
527
|
);
|
|
487
528
|
} else if ('type' in schema.additionalProperties!) {
|
|
@@ -501,12 +542,12 @@ export function stubExistingAdditionalProperties<
|
|
|
501
542
|
// The type of our new key should match the additionalProperties value;
|
|
502
543
|
schema.properties[key] = additionalProperties;
|
|
503
544
|
// Set our additional property flag so we know it was dynamically added
|
|
504
|
-
|
|
545
|
+
(schema.properties[key] as RJSFMarkedSchema)[ADDITIONAL_PROPERTY_FLAG] = true;
|
|
505
546
|
} else {
|
|
506
547
|
// Invalid property
|
|
507
548
|
schema.properties[key] = { type: 'null' };
|
|
508
549
|
// Set our additional property flag so we know it was dynamically added
|
|
509
|
-
|
|
550
|
+
(schema.properties[key] as RJSFMarkedSchema)[ADDITIONAL_PROPERTY_FLAG] = true;
|
|
510
551
|
}
|
|
511
552
|
});
|
|
512
553
|
|
|
@@ -588,11 +629,19 @@ export function retrieveSchemaInternal<
|
|
|
588
629
|
try {
|
|
589
630
|
const withContainsSchemas = [] as S[];
|
|
590
631
|
const withoutContainsSchemas = [] as S[];
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
632
|
+
// Collect Symbol-keyed properties from allOf subschemas before merging; shallowAllOfMerge
|
|
633
|
+
// (external library) only operates on string keys and will drop them.
|
|
634
|
+
const allOfSymbols: Record<symbol, unknown> = {};
|
|
635
|
+
resolvedSchema.allOf?.forEach((allOfItem) => {
|
|
636
|
+
if (typeof allOfItem === 'object' && allOfItem.contains) {
|
|
637
|
+
withContainsSchemas.push(allOfItem as S);
|
|
594
638
|
} else {
|
|
595
|
-
withoutContainsSchemas.push(
|
|
639
|
+
withoutContainsSchemas.push(allOfItem as S);
|
|
640
|
+
for (const sym of Object.getOwnPropertySymbols(allOfItem)) {
|
|
641
|
+
if (!(sym in allOfSymbols)) {
|
|
642
|
+
allOfSymbols[sym] = (allOfItem as any)[sym];
|
|
643
|
+
}
|
|
644
|
+
}
|
|
596
645
|
}
|
|
597
646
|
});
|
|
598
647
|
if (withContainsSchemas.length) {
|
|
@@ -601,10 +650,15 @@ export function retrieveSchemaInternal<
|
|
|
601
650
|
resolvedSchema = experimental_customMergeAllOf
|
|
602
651
|
? experimental_customMergeAllOf(resolvedSchema)
|
|
603
652
|
: mergeAllOf(resolvedSchema);
|
|
653
|
+
// Re-apply collected Symbol properties that the merge dropped.
|
|
654
|
+
for (const sym of Object.getOwnPropertySymbols(allOfSymbols)) {
|
|
655
|
+
(resolvedSchema as any)[sym] = allOfSymbols[sym];
|
|
656
|
+
}
|
|
604
657
|
if (withContainsSchemas.length) {
|
|
605
658
|
resolvedSchema.allOf = withContainsSchemas;
|
|
606
659
|
}
|
|
607
660
|
} catch (e) {
|
|
661
|
+
// oxlint-disable-next-line no-console
|
|
608
662
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
609
663
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
610
664
|
return resolvedSchemaWithoutAllOf as S;
|
|
@@ -612,18 +666,18 @@ export function retrieveSchemaInternal<
|
|
|
612
666
|
}
|
|
613
667
|
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
614
668
|
resolvedSchema = Object.keys(resolvedSchema.properties!).reduce(
|
|
615
|
-
(
|
|
616
|
-
const matchingProperties = getMatchingPatternProperties(
|
|
669
|
+
(acc, key) => {
|
|
670
|
+
const matchingProperties = getMatchingPatternProperties(acc, key);
|
|
617
671
|
if (!isEmpty(matchingProperties)) {
|
|
618
|
-
|
|
672
|
+
acc.properties[key] = retrieveSchema<T, S, F>(
|
|
619
673
|
validator,
|
|
620
|
-
{ allOf: [
|
|
674
|
+
{ allOf: [acc.properties[key], ...Object.values(matchingProperties)] } as S,
|
|
621
675
|
rootSchema,
|
|
622
676
|
get(rawFormData, [key]) as T,
|
|
623
677
|
experimental_customMergeAllOf,
|
|
624
678
|
);
|
|
625
679
|
}
|
|
626
|
-
return
|
|
680
|
+
return acc;
|
|
627
681
|
},
|
|
628
682
|
{
|
|
629
683
|
...resolvedSchema,
|
|
@@ -676,11 +730,7 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
676
730
|
// Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
|
|
677
731
|
const formData = rawFormData === undefined && expandAllBranches ? ({} as T) : rawFormData;
|
|
678
732
|
const discriminator = getDiscriminatorFieldFromSchema<S>(schema);
|
|
679
|
-
anyOrOneOf = anyOrOneOf.map((s) =>
|
|
680
|
-
// Due to anyOf/oneOf possibly using the same $ref we always pass a fresh recurse list array so that each option
|
|
681
|
-
// can resolve recursive references independently
|
|
682
|
-
return resolveAllReferences(s, rootSchema, []);
|
|
683
|
-
});
|
|
733
|
+
anyOrOneOf = anyOrOneOf.map((s) => resolveAllReferences(s, rootSchema, []));
|
|
684
734
|
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
685
735
|
const option = getFirstMatchingOption<T, S, F>(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
686
736
|
if (expandAllBranches) {
|
|
@@ -694,7 +744,7 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
694
744
|
getFirstMatchingOption<T, S, F>(validator, formData, relaxed, rootSchema, discriminator);
|
|
695
745
|
return anyOrOneOf.map((item) => mergeSchemas(remaining, item) as S);
|
|
696
746
|
}
|
|
697
|
-
|
|
747
|
+
return [mergeSchemas(remaining, anyOrOneOf[option]) as S];
|
|
698
748
|
}
|
|
699
749
|
return [schema];
|
|
700
750
|
}
|
|
@@ -714,15 +764,15 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
714
764
|
* @returns - A new array of plain schema objects with `additionalProperties` relaxed where needed
|
|
715
765
|
*/
|
|
716
766
|
export function relaxOptionsForScoring<S extends StrictRJSFSchema = RJSFSchema>(
|
|
717
|
-
options:
|
|
767
|
+
options: (S | boolean)[],
|
|
718
768
|
resolveRefs = false,
|
|
719
769
|
rootSchema?: S,
|
|
720
770
|
): S[] {
|
|
721
771
|
return options.map((d) => {
|
|
722
772
|
if (!isObject(d)) {
|
|
723
|
-
return (d
|
|
773
|
+
return normalizeBooleanSchema<S>(d);
|
|
724
774
|
}
|
|
725
|
-
const schema = resolveRefs && rootSchema ? resolveAllReferences<S>(d
|
|
775
|
+
const schema = resolveRefs && rootSchema ? resolveAllReferences<S>(d, rootSchema, []) : d;
|
|
726
776
|
return schema.additionalProperties === false ? { ...schema, additionalProperties: true } : schema;
|
|
727
777
|
});
|
|
728
778
|
}
|
|
@@ -799,45 +849,42 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
799
849
|
let schemas = [resolvedSchema];
|
|
800
850
|
// Process dependencies updating the local schema properties as appropriate.
|
|
801
851
|
for (const dependencyKey in dependencies) {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
808
|
-
continue;
|
|
809
|
-
}
|
|
810
|
-
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
|
|
811
|
-
dependencyKey,
|
|
812
|
-
dependencies as GenericObjectType,
|
|
813
|
-
);
|
|
814
|
-
if (Array.isArray(dependencyValue)) {
|
|
815
|
-
schemas[0] = withDependentProperties<S>(resolvedSchema, dependencyValue);
|
|
816
|
-
} else if (isObject(dependencyValue)) {
|
|
817
|
-
schemas = withDependentSchema<T, S, F>(
|
|
818
|
-
validator,
|
|
819
|
-
resolvedSchema,
|
|
820
|
-
rootSchema,
|
|
852
|
+
if (
|
|
853
|
+
(expandAllBranches || get(formData, [dependencyKey]) !== undefined) &&
|
|
854
|
+
(!resolvedSchema.properties || dependencyKey in resolvedSchema.properties)
|
|
855
|
+
) {
|
|
856
|
+
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
|
|
821
857
|
dependencyKey,
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
858
|
+
dependencies as GenericObjectType,
|
|
859
|
+
);
|
|
860
|
+
if (Array.isArray(dependencyValue)) {
|
|
861
|
+
schemas[0] = withDependentProperties<S>(resolvedSchema, dependencyValue);
|
|
862
|
+
} else if (isObject(dependencyValue)) {
|
|
863
|
+
schemas = withDependentSchema<T, S, F>(
|
|
864
|
+
validator,
|
|
865
|
+
resolvedSchema,
|
|
866
|
+
rootSchema,
|
|
867
|
+
dependencyKey,
|
|
868
|
+
dependencyValue as S,
|
|
869
|
+
expandAllBranches,
|
|
870
|
+
recurseList,
|
|
871
|
+
formData,
|
|
872
|
+
experimental_customMergeAllOf,
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
return schemas.flatMap((schema) =>
|
|
876
|
+
processDependencies<T, S, F>(
|
|
877
|
+
validator,
|
|
878
|
+
remainingDependencies,
|
|
879
|
+
schema,
|
|
880
|
+
rootSchema,
|
|
881
|
+
expandAllBranches,
|
|
882
|
+
recurseList,
|
|
883
|
+
formData,
|
|
884
|
+
experimental_customMergeAllOf,
|
|
885
|
+
),
|
|
827
886
|
);
|
|
828
887
|
}
|
|
829
|
-
return schemas.flatMap((schema) =>
|
|
830
|
-
processDependencies<T, S, F>(
|
|
831
|
-
validator,
|
|
832
|
-
remainingDependencies,
|
|
833
|
-
schema,
|
|
834
|
-
rootSchema,
|
|
835
|
-
expandAllBranches,
|
|
836
|
-
recurseList,
|
|
837
|
-
formData,
|
|
838
|
-
experimental_customMergeAllOf,
|
|
839
|
-
),
|
|
840
|
-
);
|
|
841
888
|
}
|
|
842
889
|
return schemas;
|
|
843
890
|
}
|
|
@@ -858,7 +905,7 @@ export function withDependentProperties<S extends StrictRJSFSchema = RJSFSchema>
|
|
|
858
905
|
const required = Array.isArray(schema.required)
|
|
859
906
|
? Array.from(new Set([...schema.required, ...additionallyRequired]))
|
|
860
907
|
: additionallyRequired;
|
|
861
|
-
return { ...schema, required
|
|
908
|
+
return { ...schema, required };
|
|
862
909
|
}
|
|
863
910
|
|
|
864
911
|
/** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
|
|
@@ -898,10 +945,10 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
898
945
|
);
|
|
899
946
|
return dependentSchemas.flatMap((dependent) => {
|
|
900
947
|
const { oneOf, ...dependentSchema } = dependent;
|
|
901
|
-
|
|
948
|
+
const mergedSchema = mergeSchemas(schema, dependentSchema) as S;
|
|
902
949
|
// Since it does not contain oneOf, we return the original schema.
|
|
903
950
|
if (oneOf === undefined) {
|
|
904
|
-
return
|
|
951
|
+
return mergedSchema;
|
|
905
952
|
}
|
|
906
953
|
// Resolve $refs inside oneOf.
|
|
907
954
|
const resolvedOneOfs = oneOf.map((subschema) => {
|
|
@@ -914,7 +961,7 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
914
961
|
return allPermutations.flatMap((resolvedOneOf) =>
|
|
915
962
|
withExactlyOneSubschema<T, S, F>(
|
|
916
963
|
validator,
|
|
917
|
-
|
|
964
|
+
mergedSchema,
|
|
918
965
|
rootSchema,
|
|
919
966
|
dependencyKey,
|
|
920
967
|
resolvedOneOf,
|
|
@@ -959,7 +1006,7 @@ export function withExactlyOneSubschema<
|
|
|
959
1006
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
960
1007
|
): S[] {
|
|
961
1008
|
const validSubschemas = oneOf!.filter((subschema) => {
|
|
962
|
-
if (typeof subschema === 'boolean' || !subschema
|
|
1009
|
+
if (typeof subschema === 'boolean' || !subschema?.properties) {
|
|
963
1010
|
return false;
|
|
964
1011
|
}
|
|
965
1012
|
const { [dependencyKey]: conditionPropertySchema } = subschema.properties;
|
|
@@ -975,7 +1022,8 @@ export function withExactlyOneSubschema<
|
|
|
975
1022
|
return false;
|
|
976
1023
|
});
|
|
977
1024
|
|
|
978
|
-
if (!expandAllBranches && validSubschemas
|
|
1025
|
+
if (!expandAllBranches && validSubschemas.length !== 1) {
|
|
1026
|
+
// oxlint-disable-next-line no-console
|
|
979
1027
|
console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
|
|
980
1028
|
return [schema];
|
|
981
1029
|
}
|
|
@@ -992,6 +1040,6 @@ export function withExactlyOneSubschema<
|
|
|
992
1040
|
recurseList,
|
|
993
1041
|
experimental_customMergeAllOf,
|
|
994
1042
|
);
|
|
995
|
-
return schemas.map((
|
|
1043
|
+
return schemas.map((resolvedSubschema) => mergeSchemas(schema, resolvedSubschema) as S);
|
|
996
1044
|
});
|
|
997
1045
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
|
|
4
|
-
import { PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
5
|
-
import
|
|
4
|
+
import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
5
|
+
import deepEquals from '../deepEquals';
|
|
6
|
+
import type {
|
|
6
7
|
Experimental_CustomMergeAllOf,
|
|
7
8
|
FormContextType,
|
|
8
9
|
GenericObjectType,
|
|
@@ -14,6 +15,42 @@ import retrieveSchema from './retrieveSchema';
|
|
|
14
15
|
|
|
15
16
|
const NO_VALUE = Symbol('no Value');
|
|
16
17
|
|
|
18
|
+
function enumValuesForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S): any[] | undefined {
|
|
19
|
+
if (Array.isArray(schema.enum)) {
|
|
20
|
+
return schema.enum;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const options = (schema.oneOf || schema.anyOf) as S[] | undefined;
|
|
24
|
+
if (!Array.isArray(options)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const values = options
|
|
29
|
+
.map((option) => {
|
|
30
|
+
if (CONST_KEY in option) {
|
|
31
|
+
return option[CONST_KEY];
|
|
32
|
+
}
|
|
33
|
+
return Array.isArray(option.enum) && option.enum.length === 1 ? option.enum[0] : NO_VALUE;
|
|
34
|
+
})
|
|
35
|
+
.filter((value) => value !== NO_VALUE);
|
|
36
|
+
|
|
37
|
+
return values.length > 0 ? values : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function replacementForInvalidEnumValue<S extends StrictRJSFSchema = RJSFSchema>(schema: S, formValue: any) {
|
|
41
|
+
const enumValues = enumValuesForSchema(schema);
|
|
42
|
+
if (!enumValues || enumValues.some((value) => deepEquals(value, formValue))) {
|
|
43
|
+
return NO_VALUE;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const defaultValue = get(schema, DEFAULT_KEY, NO_VALUE);
|
|
47
|
+
if (defaultValue !== NO_VALUE && enumValues.some((value) => deepEquals(value, defaultValue))) {
|
|
48
|
+
return defaultValue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return enumValues.length === 1 ? enumValues[0] : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
17
54
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
18
55
|
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
19
56
|
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
@@ -142,8 +179,8 @@ export default function sanitizeDataForNewSchema<
|
|
|
142
179
|
// Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
|
|
143
180
|
// with the new default or const. This allows the case where two schemas differ that only by the default/const
|
|
144
181
|
// value to be properly selected
|
|
145
|
-
const newOptionDefault = get(newKeyedSchema,
|
|
146
|
-
const oldOptionDefault = get(oldKeyedSchema,
|
|
182
|
+
const newOptionDefault = get(newKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
183
|
+
const oldOptionDefault = get(oldKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
147
184
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
148
185
|
if (oldOptionDefault === formValue) {
|
|
149
186
|
// If the old default matches the formValue, we'll update the new value to match the new default
|
|
@@ -154,18 +191,25 @@ export default function sanitizeDataForNewSchema<
|
|
|
154
191
|
}
|
|
155
192
|
}
|
|
156
193
|
|
|
157
|
-
const newOptionConst = get(newKeyedSchema,
|
|
158
|
-
const oldOptionConst = get(oldKeyedSchema,
|
|
194
|
+
const newOptionConst = get(newKeyedSchema, CONST_KEY, NO_VALUE);
|
|
195
|
+
const oldOptionConst = get(oldKeyedSchema, CONST_KEY, NO_VALUE);
|
|
159
196
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
160
197
|
// Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
|
|
161
198
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
|
|
162
199
|
}
|
|
200
|
+
|
|
201
|
+
if (has(data, key)) {
|
|
202
|
+
const enumReplacement = replacementForInvalidEnumValue(newKeyedSchema, formValue);
|
|
203
|
+
if (enumReplacement !== NO_VALUE) {
|
|
204
|
+
removeOldSchemaData[key] = enumReplacement;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
163
207
|
}
|
|
164
208
|
}
|
|
165
209
|
});
|
|
166
210
|
|
|
167
211
|
newFormData = {
|
|
168
|
-
...(typeof data
|
|
212
|
+
...(typeof data === 'string' || Array.isArray(data) ? undefined : data),
|
|
169
213
|
...removeOldSchemaData,
|
|
170
214
|
...nestedData,
|
|
171
215
|
};
|
|
@@ -221,7 +265,12 @@ export default function sanitizeDataForNewSchema<
|
|
|
221
265
|
return newValue;
|
|
222
266
|
}, []);
|
|
223
267
|
} else {
|
|
224
|
-
|
|
268
|
+
// Filter out items that are no longer valid in the new items schema (e.g., enum values that changed)
|
|
269
|
+
const newItemEnumValues = enumValuesForSchema(newSchemaItems as S);
|
|
270
|
+
const filteredData = newItemEnumValues
|
|
271
|
+
? data.filter((item: any) => newItemEnumValues.some((v: any) => deepEquals(v, item)))
|
|
272
|
+
: data;
|
|
273
|
+
newFormData = maxItems > 0 && filteredData.length > maxItems ? filteredData.slice(0, maxItems) : filteredData;
|
|
225
274
|
}
|
|
226
275
|
}
|
|
227
276
|
} else if (
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// oxlint-disable typescript/no-deprecated
|
|
1
2
|
import get from 'lodash/get';
|
|
2
3
|
import isObject from 'lodash/isObject';
|
|
3
4
|
import set from 'lodash/set';
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
} from '../constants';
|
|
18
19
|
import deepEquals from '../deepEquals';
|
|
19
20
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
20
|
-
import {
|
|
21
|
+
import type {
|
|
21
22
|
Experimental_CustomMergeAllOf,
|
|
22
23
|
FormContextType,
|
|
23
24
|
GenericObjectType,
|
|
@@ -51,16 +52,16 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
51
52
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
52
53
|
): PathSchema<T> {
|
|
53
54
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
54
|
-
const
|
|
55
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item,
|
|
55
|
+
const innerSchema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
56
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, innerSchema));
|
|
56
57
|
if (sameSchemaIndex === -1) {
|
|
57
58
|
return toPathSchemaInternal<T, S, F>(
|
|
58
59
|
validator,
|
|
59
|
-
|
|
60
|
+
innerSchema,
|
|
60
61
|
name,
|
|
61
62
|
rootSchema,
|
|
62
63
|
formData,
|
|
63
|
-
_recurseList.concat(
|
|
64
|
+
_recurseList.concat(innerSchema),
|
|
64
65
|
experimental_customMergeAllOf,
|
|
65
66
|
);
|
|
66
67
|
}
|
|
@@ -82,12 +83,12 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
82
83
|
discriminator,
|
|
83
84
|
experimental_customMergeAllOf,
|
|
84
85
|
);
|
|
85
|
-
const
|
|
86
|
+
const innerSchema: S = xxxOf[index];
|
|
86
87
|
pathSchema = {
|
|
87
88
|
...pathSchema,
|
|
88
89
|
...toPathSchemaInternal<T, S, F>(
|
|
89
90
|
validator,
|
|
90
|
-
|
|
91
|
+
innerSchema,
|
|
91
92
|
name,
|
|
92
93
|
rootSchema,
|
|
93
94
|
formData,
|
|
@@ -144,6 +145,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
144
145
|
experimental_customMergeAllOf,
|
|
145
146
|
);
|
|
146
147
|
} else {
|
|
148
|
+
// oxlint-disable-next-line no-console
|
|
147
149
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
148
150
|
}
|
|
149
151
|
});
|
|
@@ -161,6 +163,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
} else if (PROPERTIES_KEY in schema) {
|
|
166
|
+
// This is a deprecated function that is no longer used by RJSF
|
|
167
|
+
// oxlint-disable-next-line guard-for-in
|
|
164
168
|
for (const property in schema.properties) {
|
|
165
169
|
const field: S = get(schema, [PROPERTIES_KEY, property], {}) as S;
|
|
166
170
|
(pathSchema as PathSchema<GenericObjectType>)[property] = toPathSchemaInternal<T, S, F>(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
2
|
|
|
3
3
|
/** Check to see if a `schema` specifies that a value must be true. This happens when:
|
|
4
4
|
* - `schema.const` is truthy
|
|
@@ -16,17 +16,17 @@ export default function schemaRequiresTrueValue<S extends StrictRJSFSchema = RJS
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// Check if an enum has a single value of true
|
|
19
|
-
if (schema.enum
|
|
19
|
+
if (schema.enum?.length === 1 && schema.enum[0] === true) {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// If anyOf has a single value, evaluate the subschema
|
|
24
|
-
if (schema.anyOf
|
|
24
|
+
if (schema.anyOf?.length === 1) {
|
|
25
25
|
return schemaRequiresTrueValue(schema.anyOf[0] as S);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// If oneOf has a single value, evaluate the subschema
|
|
29
|
-
if (schema.oneOf
|
|
29
|
+
if (schema.oneOf?.length === 1) {
|
|
30
30
|
return schemaRequiresTrueValue(schema.oneOf[0] as S);
|
|
31
31
|
}
|
|
32
32
|
|