@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1347 -642
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1324 -619
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1266 -590
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +2 -2
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +15 -3
- package/lib/constants.js +15 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +5 -3
- package/lib/findSchemaDefinition.js +54 -11
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +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 +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +316 -167
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +30 -12
- package/lib/schema/retrieveSchema.js +153 -70
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +172 -142
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +37 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +17 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +55 -10
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +461 -193
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +268 -78
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +278 -184
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
2
|
import set from 'lodash/set';
|
|
4
3
|
import times from 'lodash/times';
|
|
5
4
|
import transform from 'lodash/transform';
|
|
@@ -14,19 +13,30 @@ import {
|
|
|
14
13
|
ALL_OF_KEY,
|
|
15
14
|
ANY_OF_KEY,
|
|
16
15
|
DEPENDENCIES_KEY,
|
|
16
|
+
ID_KEY,
|
|
17
17
|
IF_KEY,
|
|
18
|
+
ITEMS_KEY,
|
|
18
19
|
ONE_OF_KEY,
|
|
19
|
-
|
|
20
|
+
PATTERN_PROPERTIES_KEY,
|
|
20
21
|
PROPERTIES_KEY,
|
|
21
|
-
|
|
22
|
+
REF_KEY,
|
|
22
23
|
} from '../constants';
|
|
23
24
|
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition';
|
|
24
25
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
25
26
|
import guessType from '../guessType';
|
|
26
27
|
import isObject from '../isObject';
|
|
27
28
|
import mergeSchemas from '../mergeSchemas';
|
|
28
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
Experimental_CustomMergeAllOf,
|
|
31
|
+
FormContextType,
|
|
32
|
+
GenericObjectType,
|
|
33
|
+
RJSFSchema,
|
|
34
|
+
StrictRJSFSchema,
|
|
35
|
+
ValidatorType,
|
|
36
|
+
} from '../types';
|
|
29
37
|
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
38
|
+
import deepEquals from '../deepEquals';
|
|
39
|
+
import isEmpty from 'lodash/isEmpty';
|
|
30
40
|
|
|
31
41
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
32
42
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
@@ -36,14 +46,29 @@ import getFirstMatchingOption from './getFirstMatchingOption';
|
|
|
36
46
|
* @param schema - The schema for which retrieving a schema is desired
|
|
37
47
|
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
38
48
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
49
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
39
50
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
40
51
|
*/
|
|
41
52
|
export default function retrieveSchema<
|
|
42
53
|
T = any,
|
|
43
54
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
44
|
-
F extends FormContextType = any
|
|
45
|
-
>(
|
|
46
|
-
|
|
55
|
+
F extends FormContextType = any,
|
|
56
|
+
>(
|
|
57
|
+
validator: ValidatorType<T, S, F>,
|
|
58
|
+
schema: S,
|
|
59
|
+
rootSchema: S = {} as S,
|
|
60
|
+
rawFormData?: T,
|
|
61
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
62
|
+
): S {
|
|
63
|
+
return retrieveSchemaInternal<T, S, F>(
|
|
64
|
+
validator,
|
|
65
|
+
schema,
|
|
66
|
+
rootSchema,
|
|
67
|
+
rawFormData,
|
|
68
|
+
undefined,
|
|
69
|
+
undefined,
|
|
70
|
+
experimental_customMergeAllOf,
|
|
71
|
+
)[0];
|
|
47
72
|
}
|
|
48
73
|
|
|
49
74
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
@@ -57,6 +82,7 @@ export default function retrieveSchema<
|
|
|
57
82
|
* dependencies as a list of schemas
|
|
58
83
|
* @param recurseList - The list of recursive references already processed
|
|
59
84
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
85
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
60
86
|
* @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
|
|
61
87
|
*/
|
|
62
88
|
export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -65,7 +91,8 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
65
91
|
rootSchema: S,
|
|
66
92
|
expandAllBranches: boolean,
|
|
67
93
|
recurseList: string[],
|
|
68
|
-
formData?: T
|
|
94
|
+
formData?: T,
|
|
95
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
69
96
|
): S[] {
|
|
70
97
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
71
98
|
|
|
@@ -75,12 +102,28 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
75
102
|
if (expandAllBranches) {
|
|
76
103
|
if (then && typeof then !== 'boolean') {
|
|
77
104
|
schemas = schemas.concat(
|
|
78
|
-
retrieveSchemaInternal<T, S, F>(
|
|
105
|
+
retrieveSchemaInternal<T, S, F>(
|
|
106
|
+
validator,
|
|
107
|
+
then as S,
|
|
108
|
+
rootSchema,
|
|
109
|
+
formData,
|
|
110
|
+
expandAllBranches,
|
|
111
|
+
recurseList,
|
|
112
|
+
experimental_customMergeAllOf,
|
|
113
|
+
),
|
|
79
114
|
);
|
|
80
115
|
}
|
|
81
116
|
if (otherwise && typeof otherwise !== 'boolean') {
|
|
82
117
|
schemas = schemas.concat(
|
|
83
|
-
retrieveSchemaInternal<T, S, F>(
|
|
118
|
+
retrieveSchemaInternal<T, S, F>(
|
|
119
|
+
validator,
|
|
120
|
+
otherwise as S,
|
|
121
|
+
rootSchema,
|
|
122
|
+
formData,
|
|
123
|
+
expandAllBranches,
|
|
124
|
+
recurseList,
|
|
125
|
+
experimental_customMergeAllOf,
|
|
126
|
+
),
|
|
84
127
|
);
|
|
85
128
|
}
|
|
86
129
|
} else {
|
|
@@ -93,8 +136,9 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
93
136
|
rootSchema,
|
|
94
137
|
formData,
|
|
95
138
|
expandAllBranches,
|
|
96
|
-
recurseList
|
|
97
|
-
|
|
139
|
+
recurseList,
|
|
140
|
+
experimental_customMergeAllOf,
|
|
141
|
+
),
|
|
98
142
|
);
|
|
99
143
|
}
|
|
100
144
|
}
|
|
@@ -102,7 +146,15 @@ export function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
102
146
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s) as S);
|
|
103
147
|
}
|
|
104
148
|
return resolvedSchemas.flatMap((s) =>
|
|
105
|
-
retrieveSchemaInternal<T, S, F>(
|
|
149
|
+
retrieveSchemaInternal<T, S, F>(
|
|
150
|
+
validator,
|
|
151
|
+
s,
|
|
152
|
+
rootSchema,
|
|
153
|
+
formData,
|
|
154
|
+
expandAllBranches,
|
|
155
|
+
recurseList,
|
|
156
|
+
experimental_customMergeAllOf,
|
|
157
|
+
),
|
|
106
158
|
);
|
|
107
159
|
}
|
|
108
160
|
|
|
@@ -131,12 +183,34 @@ export function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchem
|
|
|
131
183
|
permutations.forEach((permutation) => permutation.push(list[0]));
|
|
132
184
|
return permutations;
|
|
133
185
|
},
|
|
134
|
-
[[]] as S[][] // Start with an empty list
|
|
186
|
+
[[]] as S[][], // Start with an empty list
|
|
135
187
|
);
|
|
136
188
|
|
|
137
189
|
return allPermutations;
|
|
138
190
|
}
|
|
139
191
|
|
|
192
|
+
/** Returns the subset of 'patternProperties' specifications that match the given 'key'
|
|
193
|
+
*
|
|
194
|
+
* @param schema - The schema whose 'patternProperties' are to be filtered
|
|
195
|
+
* @param key - The key to match against the 'patternProperties' specifications
|
|
196
|
+
* @returns - The subset of 'patternProperties' specifications that match the given 'key'
|
|
197
|
+
*/
|
|
198
|
+
export function getMatchingPatternProperties<S extends StrictRJSFSchema = RJSFSchema>(
|
|
199
|
+
schema: S,
|
|
200
|
+
key: string,
|
|
201
|
+
): Required<S['patternProperties']> {
|
|
202
|
+
return Object.keys(schema.patternProperties!)
|
|
203
|
+
.filter((pattern: string) => RegExp(pattern).test(key))
|
|
204
|
+
.reduce(
|
|
205
|
+
(obj, pattern) => {
|
|
206
|
+
// Pass the pattern using the `[]` index notation so that any `.` in the pattern are not used as a dotted path
|
|
207
|
+
set(obj, [pattern], schema.patternProperties![pattern]);
|
|
208
|
+
return obj;
|
|
209
|
+
},
|
|
210
|
+
{} as Required<S['patternProperties']>,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
140
214
|
/** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
|
|
141
215
|
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
|
|
142
216
|
* `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
|
|
@@ -148,6 +222,7 @@ export function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchem
|
|
|
148
222
|
* as a list of schemas
|
|
149
223
|
* @param recurseList - The list of recursive references already processed
|
|
150
224
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
225
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
151
226
|
* @returns - The list of schemas having its references, dependencies and allOf schemas resolved
|
|
152
227
|
*/
|
|
153
228
|
export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -156,7 +231,8 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
156
231
|
rootSchema: S,
|
|
157
232
|
expandAllBranches: boolean,
|
|
158
233
|
recurseList: string[],
|
|
159
|
-
formData?: T
|
|
234
|
+
formData?: T,
|
|
235
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
160
236
|
): S[] {
|
|
161
237
|
const updatedSchemas = resolveReference<T, S, F>(
|
|
162
238
|
validator,
|
|
@@ -164,7 +240,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
164
240
|
rootSchema,
|
|
165
241
|
expandAllBranches,
|
|
166
242
|
recurseList,
|
|
167
|
-
formData
|
|
243
|
+
formData,
|
|
168
244
|
);
|
|
169
245
|
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
170
246
|
// return the updatedSchemas array if it has either multiple schemas within it
|
|
@@ -178,10 +254,18 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
178
254
|
rootSchema,
|
|
179
255
|
expandAllBranches,
|
|
180
256
|
recurseList,
|
|
181
|
-
formData
|
|
257
|
+
formData,
|
|
182
258
|
);
|
|
183
259
|
return resolvedSchemas.flatMap((s) => {
|
|
184
|
-
return retrieveSchemaInternal<T, S, F>(
|
|
260
|
+
return retrieveSchemaInternal<T, S, F>(
|
|
261
|
+
validator,
|
|
262
|
+
s,
|
|
263
|
+
rootSchema,
|
|
264
|
+
formData,
|
|
265
|
+
expandAllBranches,
|
|
266
|
+
recurseList,
|
|
267
|
+
experimental_customMergeAllOf,
|
|
268
|
+
);
|
|
185
269
|
});
|
|
186
270
|
}
|
|
187
271
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -192,11 +276,15 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
192
276
|
rootSchema,
|
|
193
277
|
formData,
|
|
194
278
|
expandAllBranches,
|
|
195
|
-
recurseList
|
|
196
|
-
|
|
279
|
+
recurseList,
|
|
280
|
+
experimental_customMergeAllOf,
|
|
281
|
+
),
|
|
197
282
|
);
|
|
198
283
|
const allPermutations = getAllPermutationsOfXxxOf<S>(allOfSchemaElements);
|
|
199
|
-
return allPermutations.map((permutation) => ({
|
|
284
|
+
return allPermutations.map((permutation) => ({
|
|
285
|
+
...schema,
|
|
286
|
+
allOf: permutation,
|
|
287
|
+
}));
|
|
200
288
|
}
|
|
201
289
|
// No $ref or dependencies or allOf attribute was found, returning the original schema.
|
|
202
290
|
return [schema];
|
|
@@ -213,6 +301,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
213
301
|
* as a list of schemas
|
|
214
302
|
* @param recurseList - The list of recursive references already processed
|
|
215
303
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
304
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
216
305
|
* @returns - The list schemas retrieved after having all references resolved
|
|
217
306
|
*/
|
|
218
307
|
export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -221,7 +310,8 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
221
310
|
rootSchema: S,
|
|
222
311
|
expandAllBranches: boolean,
|
|
223
312
|
recurseList: string[],
|
|
224
|
-
formData?: T
|
|
313
|
+
formData?: T,
|
|
314
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
225
315
|
): S[] {
|
|
226
316
|
const updatedSchema = resolveAllReferences<S>(schema, rootSchema, recurseList);
|
|
227
317
|
if (updatedSchema !== schema) {
|
|
@@ -232,7 +322,8 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
232
322
|
rootSchema,
|
|
233
323
|
formData,
|
|
234
324
|
expandAllBranches,
|
|
235
|
-
recurseList
|
|
325
|
+
recurseList,
|
|
326
|
+
experimental_customMergeAllOf,
|
|
236
327
|
);
|
|
237
328
|
}
|
|
238
329
|
return [schema];
|
|
@@ -243,12 +334,14 @@ export function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
243
334
|
* @param schema - The schema for which resolving all references is desired
|
|
244
335
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
245
336
|
* @param recurseList - List of $refs already resolved to prevent recursion
|
|
337
|
+
* @param [baseURI] - The base URI to be used for resolving relative references
|
|
246
338
|
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved
|
|
247
339
|
*/
|
|
248
340
|
export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
249
341
|
schema: S,
|
|
250
342
|
rootSchema: S,
|
|
251
|
-
recurseList: string[]
|
|
343
|
+
recurseList: string[],
|
|
344
|
+
baseURI?: string,
|
|
252
345
|
): S {
|
|
253
346
|
if (!isObject(schema)) {
|
|
254
347
|
return schema;
|
|
@@ -263,8 +356,11 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
263
356
|
}
|
|
264
357
|
recurseList.push($ref!);
|
|
265
358
|
// Retrieve the referenced schema definition.
|
|
266
|
-
const refSchema = findSchemaDefinition<S>($ref, rootSchema);
|
|
359
|
+
const refSchema = findSchemaDefinition<S>($ref, rootSchema, baseURI);
|
|
267
360
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
361
|
+
if (ID_KEY in resolvedSchema) {
|
|
362
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
363
|
+
}
|
|
268
364
|
}
|
|
269
365
|
|
|
270
366
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
@@ -273,10 +369,10 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
273
369
|
resolvedSchema[PROPERTIES_KEY]!,
|
|
274
370
|
(result, value, key: string) => {
|
|
275
371
|
const childList: string[] = [...recurseList];
|
|
276
|
-
result[key] = resolveAllReferences(value as S, rootSchema, childList);
|
|
372
|
+
result[key] = resolveAllReferences(value as S, rootSchema, childList, baseURI);
|
|
277
373
|
childrenLists.push(childList);
|
|
278
374
|
},
|
|
279
|
-
{} as RJSFSchema
|
|
375
|
+
{} as RJSFSchema,
|
|
280
376
|
);
|
|
281
377
|
merge(recurseList, uniq(flattenDeep(childrenLists)));
|
|
282
378
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
@@ -289,11 +385,11 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
289
385
|
) {
|
|
290
386
|
resolvedSchema = {
|
|
291
387
|
...resolvedSchema,
|
|
292
|
-
items: resolveAllReferences(resolvedSchema.items as S, rootSchema, recurseList),
|
|
388
|
+
items: resolveAllReferences(resolvedSchema.items as S, rootSchema, recurseList, baseURI),
|
|
293
389
|
};
|
|
294
390
|
}
|
|
295
391
|
|
|
296
|
-
return
|
|
392
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
297
393
|
}
|
|
298
394
|
|
|
299
395
|
/** Creates new 'properties' items for each key in the `formData`
|
|
@@ -302,13 +398,20 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
302
398
|
* @param theSchema - The schema for which the existing additional properties is desired
|
|
303
399
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
|
|
304
400
|
* @param [aFormData] - The current formData, if any, to assist retrieving a schema
|
|
401
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
305
402
|
* @returns - The updated schema with additional properties stubbed
|
|
306
403
|
*/
|
|
307
404
|
export function stubExistingAdditionalProperties<
|
|
308
405
|
T = any,
|
|
309
406
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
310
|
-
F extends FormContextType = any
|
|
311
|
-
>(
|
|
407
|
+
F extends FormContextType = any,
|
|
408
|
+
>(
|
|
409
|
+
validator: ValidatorType<T, S, F>,
|
|
410
|
+
theSchema: S,
|
|
411
|
+
rootSchema?: S,
|
|
412
|
+
aFormData?: T,
|
|
413
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
414
|
+
): S {
|
|
312
415
|
// Clone the schema so that we don't ruin the consumer's original
|
|
313
416
|
const schema = {
|
|
314
417
|
...theSchema,
|
|
@@ -322,34 +425,55 @@ export function stubExistingAdditionalProperties<
|
|
|
322
425
|
// No need to stub, our schema already has the property
|
|
323
426
|
return;
|
|
324
427
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
additionalProperties = retrieveSchema<T, S, F>(
|
|
428
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
429
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
430
|
+
if (!isEmpty(matchingProperties)) {
|
|
431
|
+
schema.properties[key] = retrieveSchema<T, S, F>(
|
|
330
432
|
validator,
|
|
331
|
-
{
|
|
433
|
+
{ allOf: Object.values(matchingProperties) } as S,
|
|
332
434
|
rootSchema,
|
|
333
|
-
formData as T
|
|
435
|
+
get(formData, [key]) as T,
|
|
436
|
+
experimental_customMergeAllOf,
|
|
334
437
|
);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
438
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
443
|
+
let additionalProperties: S['additionalProperties'] = {};
|
|
444
|
+
if (typeof schema.additionalProperties !== 'boolean') {
|
|
445
|
+
if (REF_KEY in schema.additionalProperties!) {
|
|
446
|
+
additionalProperties = retrieveSchema<T, S, F>(
|
|
447
|
+
validator,
|
|
448
|
+
{ $ref: get(schema.additionalProperties, [REF_KEY]) } as S,
|
|
449
|
+
rootSchema,
|
|
450
|
+
formData as T,
|
|
451
|
+
experimental_customMergeAllOf,
|
|
452
|
+
);
|
|
453
|
+
} else if ('type' in schema.additionalProperties!) {
|
|
454
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
455
|
+
} else if (ANY_OF_KEY in schema.additionalProperties! || ONE_OF_KEY in schema.additionalProperties!) {
|
|
456
|
+
additionalProperties = {
|
|
457
|
+
type: 'object',
|
|
458
|
+
...schema.additionalProperties,
|
|
459
|
+
};
|
|
460
|
+
} else {
|
|
461
|
+
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
462
|
+
}
|
|
342
463
|
} else {
|
|
343
464
|
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
344
465
|
}
|
|
466
|
+
|
|
467
|
+
// The type of our new key should match the additionalProperties value;
|
|
468
|
+
schema.properties[key] = additionalProperties;
|
|
469
|
+
// Set our additional property flag so we know it was dynamically added
|
|
470
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
345
471
|
} else {
|
|
346
|
-
|
|
472
|
+
// Invalid property
|
|
473
|
+
schema.properties[key] = { type: 'null' };
|
|
474
|
+
// Set our additional property flag so we know it was dynamically added
|
|
475
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
347
476
|
}
|
|
348
|
-
|
|
349
|
-
// The type of our new key should match the additionalProperties value;
|
|
350
|
-
schema.properties[key] = additionalProperties;
|
|
351
|
-
// Set our additional property flag so we know it was dynamically added
|
|
352
|
-
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
353
477
|
});
|
|
354
478
|
|
|
355
479
|
return schema;
|
|
@@ -367,20 +491,22 @@ export function stubExistingAdditionalProperties<
|
|
|
367
491
|
* @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
|
|
368
492
|
* dependencies as a list of schemas
|
|
369
493
|
* @param [recurseList=[]] - The optional, list of recursive references already processed
|
|
494
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
370
495
|
* @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
|
|
371
496
|
* resolved. Multiple schemas may be returned if `expandAllBranches` is true.
|
|
372
497
|
*/
|
|
373
498
|
export function retrieveSchemaInternal<
|
|
374
499
|
T = any,
|
|
375
500
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
376
|
-
F extends FormContextType = any
|
|
501
|
+
F extends FormContextType = any,
|
|
377
502
|
>(
|
|
378
503
|
validator: ValidatorType<T, S, F>,
|
|
379
504
|
schema: S,
|
|
380
505
|
rootSchema: S,
|
|
381
506
|
rawFormData?: T,
|
|
382
507
|
expandAllBranches = false,
|
|
383
|
-
recurseList: string[] = []
|
|
508
|
+
recurseList: string[] = [],
|
|
509
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
384
510
|
): S[] {
|
|
385
511
|
if (!isObject(schema)) {
|
|
386
512
|
return [{} as S];
|
|
@@ -391,7 +517,8 @@ export function retrieveSchemaInternal<
|
|
|
391
517
|
rootSchema,
|
|
392
518
|
expandAllBranches,
|
|
393
519
|
recurseList,
|
|
394
|
-
rawFormData
|
|
520
|
+
rawFormData,
|
|
521
|
+
experimental_customMergeAllOf,
|
|
395
522
|
);
|
|
396
523
|
return resolvedSchemas.flatMap((s: S) => {
|
|
397
524
|
let resolvedSchema = s;
|
|
@@ -402,7 +529,8 @@ export function retrieveSchemaInternal<
|
|
|
402
529
|
rootSchema,
|
|
403
530
|
expandAllBranches,
|
|
404
531
|
recurseList,
|
|
405
|
-
rawFormData as T
|
|
532
|
+
rawFormData as T,
|
|
533
|
+
experimental_customMergeAllOf,
|
|
406
534
|
);
|
|
407
535
|
}
|
|
408
536
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -412,19 +540,67 @@ export function retrieveSchemaInternal<
|
|
|
412
540
|
return [...(allOf as S[]), restOfSchema as S];
|
|
413
541
|
}
|
|
414
542
|
try {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
543
|
+
const withContainsSchemas = [] as S[];
|
|
544
|
+
const withoutContainsSchemas = [] as S[];
|
|
545
|
+
resolvedSchema.allOf?.forEach((s) => {
|
|
546
|
+
if (typeof s === 'object' && s.contains) {
|
|
547
|
+
withContainsSchemas.push(s as S);
|
|
548
|
+
} else {
|
|
549
|
+
withoutContainsSchemas.push(s as S);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
if (withContainsSchemas.length) {
|
|
553
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
554
|
+
}
|
|
555
|
+
resolvedSchema = experimental_customMergeAllOf
|
|
556
|
+
? experimental_customMergeAllOf(resolvedSchema)
|
|
557
|
+
: (mergeAllOf(resolvedSchema, {
|
|
558
|
+
deep: false,
|
|
559
|
+
resolvers: {
|
|
560
|
+
$defs: mergeAllOf.options.resolvers.definitions,
|
|
561
|
+
},
|
|
562
|
+
} as Options) as S);
|
|
563
|
+
if (withContainsSchemas.length) {
|
|
564
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
565
|
+
}
|
|
418
566
|
} catch (e) {
|
|
419
567
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
420
568
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
421
569
|
return resolvedSchemaWithoutAllOf as S;
|
|
422
570
|
}
|
|
423
571
|
}
|
|
572
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
573
|
+
resolvedSchema = Object.keys(resolvedSchema.properties!).reduce(
|
|
574
|
+
(schema, key) => {
|
|
575
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
576
|
+
if (!isEmpty(matchingProperties)) {
|
|
577
|
+
schema.properties[key] = retrieveSchema<T, S, F>(
|
|
578
|
+
validator,
|
|
579
|
+
{ allOf: [schema.properties[key], ...Object.values(matchingProperties)] } as S,
|
|
580
|
+
rootSchema,
|
|
581
|
+
get(rawFormData, [key]) as T,
|
|
582
|
+
experimental_customMergeAllOf,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return schema;
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
...resolvedSchema,
|
|
589
|
+
properties: { ...resolvedSchema.properties },
|
|
590
|
+
},
|
|
591
|
+
);
|
|
592
|
+
}
|
|
424
593
|
const hasAdditionalProperties =
|
|
425
|
-
|
|
594
|
+
PATTERN_PROPERTIES_KEY in resolvedSchema ||
|
|
595
|
+
(ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false);
|
|
426
596
|
if (hasAdditionalProperties) {
|
|
427
|
-
return stubExistingAdditionalProperties<T, S, F>(
|
|
597
|
+
return stubExistingAdditionalProperties<T, S, F>(
|
|
598
|
+
validator,
|
|
599
|
+
resolvedSchema,
|
|
600
|
+
rootSchema,
|
|
601
|
+
rawFormData as T,
|
|
602
|
+
experimental_customMergeAllOf,
|
|
603
|
+
);
|
|
428
604
|
}
|
|
429
605
|
|
|
430
606
|
return resolvedSchema;
|
|
@@ -446,7 +622,7 @@ export function retrieveSchemaInternal<
|
|
|
446
622
|
export function resolveAnyOrOneOfSchemas<
|
|
447
623
|
T = any,
|
|
448
624
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
449
|
-
F extends FormContextType = any
|
|
625
|
+
F extends FormContextType = any,
|
|
450
626
|
>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, rawFormData?: T) {
|
|
451
627
|
let anyOrOneOf: S[] | undefined;
|
|
452
628
|
const { oneOf, anyOf, ...remaining } = schema;
|
|
@@ -484,6 +660,7 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
484
660
|
* as a list of schemas
|
|
485
661
|
* @param recurseList - The list of recursive references already processed
|
|
486
662
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
663
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
487
664
|
* @returns - The list of schemas with their dependencies resolved
|
|
488
665
|
*/
|
|
489
666
|
export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -492,7 +669,8 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
492
669
|
rootSchema: S,
|
|
493
670
|
expandAllBranches: boolean,
|
|
494
671
|
recurseList: string[],
|
|
495
|
-
formData?: T
|
|
672
|
+
formData?: T,
|
|
673
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
496
674
|
): S[] {
|
|
497
675
|
// Drop the dependencies from the source schema.
|
|
498
676
|
const { dependencies, ...remainingSchema } = schema;
|
|
@@ -501,7 +679,7 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
501
679
|
remainingSchema as S,
|
|
502
680
|
rootSchema,
|
|
503
681
|
expandAllBranches,
|
|
504
|
-
formData
|
|
682
|
+
formData,
|
|
505
683
|
);
|
|
506
684
|
return resolvedSchemas.flatMap((resolvedSchema) =>
|
|
507
685
|
processDependencies<T, S, F>(
|
|
@@ -511,8 +689,9 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
511
689
|
rootSchema,
|
|
512
690
|
expandAllBranches,
|
|
513
691
|
recurseList,
|
|
514
|
-
formData
|
|
515
|
-
|
|
692
|
+
formData,
|
|
693
|
+
experimental_customMergeAllOf,
|
|
694
|
+
),
|
|
516
695
|
);
|
|
517
696
|
}
|
|
518
697
|
|
|
@@ -527,6 +706,7 @@ export function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
527
706
|
* as a list of schemas
|
|
528
707
|
* @param recurseList - The list of recursive references already processed
|
|
529
708
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
709
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
530
710
|
* @returns - The schema with the `dependencies` resolved into it
|
|
531
711
|
*/
|
|
532
712
|
export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -536,7 +716,8 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
536
716
|
rootSchema: S,
|
|
537
717
|
expandAllBranches: boolean,
|
|
538
718
|
recurseList: string[],
|
|
539
|
-
formData?: T
|
|
719
|
+
formData?: T,
|
|
720
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
540
721
|
): S[] {
|
|
541
722
|
let schemas = [resolvedSchema];
|
|
542
723
|
// Process dependencies updating the local schema properties as appropriate.
|
|
@@ -551,7 +732,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
551
732
|
}
|
|
552
733
|
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
|
|
553
734
|
dependencyKey,
|
|
554
|
-
dependencies as GenericObjectType
|
|
735
|
+
dependencies as GenericObjectType,
|
|
555
736
|
);
|
|
556
737
|
if (Array.isArray(dependencyValue)) {
|
|
557
738
|
schemas[0] = withDependentProperties<S>(resolvedSchema, dependencyValue);
|
|
@@ -564,7 +745,8 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
564
745
|
dependencyValue as S,
|
|
565
746
|
expandAllBranches,
|
|
566
747
|
recurseList,
|
|
567
|
-
formData
|
|
748
|
+
formData,
|
|
749
|
+
experimental_customMergeAllOf,
|
|
568
750
|
);
|
|
569
751
|
}
|
|
570
752
|
return schemas.flatMap((schema) =>
|
|
@@ -575,8 +757,9 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
575
757
|
rootSchema,
|
|
576
758
|
expandAllBranches,
|
|
577
759
|
recurseList,
|
|
578
|
-
formData
|
|
579
|
-
|
|
760
|
+
formData,
|
|
761
|
+
experimental_customMergeAllOf,
|
|
762
|
+
),
|
|
580
763
|
);
|
|
581
764
|
}
|
|
582
765
|
return schemas;
|
|
@@ -590,7 +773,7 @@ export function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
590
773
|
*/
|
|
591
774
|
export function withDependentProperties<S extends StrictRJSFSchema = RJSFSchema>(
|
|
592
775
|
schema: S,
|
|
593
|
-
additionallyRequired?: string[]
|
|
776
|
+
additionallyRequired?: string[],
|
|
594
777
|
) {
|
|
595
778
|
if (!additionallyRequired) {
|
|
596
779
|
return schema;
|
|
@@ -613,6 +796,7 @@ export function withDependentProperties<S extends StrictRJSFSchema = RJSFSchema>
|
|
|
613
796
|
* as a list of schemas
|
|
614
797
|
* @param recurseList - The list of recursive references already processed
|
|
615
798
|
* @param [formData]- The current formData to assist retrieving a schema
|
|
799
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
616
800
|
* @returns - The list of schemas with the dependent schema resolved into them
|
|
617
801
|
*/
|
|
618
802
|
export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -623,7 +807,8 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
623
807
|
dependencyValue: S,
|
|
624
808
|
expandAllBranches: boolean,
|
|
625
809
|
recurseList: string[],
|
|
626
|
-
formData?: T
|
|
810
|
+
formData?: T,
|
|
811
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
627
812
|
): S[] {
|
|
628
813
|
const dependentSchemas = retrieveSchemaInternal<T, S, F>(
|
|
629
814
|
validator,
|
|
@@ -631,7 +816,8 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
631
816
|
rootSchema,
|
|
632
817
|
formData,
|
|
633
818
|
expandAllBranches,
|
|
634
|
-
recurseList
|
|
819
|
+
recurseList,
|
|
820
|
+
experimental_customMergeAllOf,
|
|
635
821
|
);
|
|
636
822
|
return dependentSchemas.flatMap((dependent) => {
|
|
637
823
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -657,8 +843,9 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
657
843
|
resolvedOneOf,
|
|
658
844
|
expandAllBranches,
|
|
659
845
|
recurseList,
|
|
660
|
-
formData
|
|
661
|
-
|
|
846
|
+
formData,
|
|
847
|
+
experimental_customMergeAllOf,
|
|
848
|
+
),
|
|
662
849
|
);
|
|
663
850
|
});
|
|
664
851
|
}
|
|
@@ -676,12 +863,13 @@ export function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
676
863
|
* as a list of schemas
|
|
677
864
|
* @param recurseList - The list of recursive references already processed
|
|
678
865
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
866
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
679
867
|
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
680
868
|
*/
|
|
681
869
|
export function withExactlyOneSubschema<
|
|
682
870
|
T = any,
|
|
683
871
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
684
|
-
F extends FormContextType = any
|
|
872
|
+
F extends FormContextType = any,
|
|
685
873
|
>(
|
|
686
874
|
validator: ValidatorType<T, S, F>,
|
|
687
875
|
schema: S,
|
|
@@ -690,7 +878,8 @@ export function withExactlyOneSubschema<
|
|
|
690
878
|
oneOf: S['oneOf'],
|
|
691
879
|
expandAllBranches: boolean,
|
|
692
880
|
recurseList: string[],
|
|
693
|
-
formData?: T
|
|
881
|
+
formData?: T,
|
|
882
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
694
883
|
): S[] {
|
|
695
884
|
const validSubschemas = oneOf!.filter((subschema) => {
|
|
696
885
|
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
@@ -723,7 +912,8 @@ export function withExactlyOneSubschema<
|
|
|
723
912
|
rootSchema,
|
|
724
913
|
formData,
|
|
725
914
|
expandAllBranches,
|
|
726
|
-
recurseList
|
|
915
|
+
recurseList,
|
|
916
|
+
experimental_customMergeAllOf,
|
|
727
917
|
);
|
|
728
918
|
return schemas.map((s) => mergeSchemas(schema, s) as S);
|
|
729
919
|
});
|