@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,4 +1,4 @@
|
|
|
1
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
1
|
+
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
|
|
2
2
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
3
3
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
4
4
|
* potentially recursive resolution.
|
|
@@ -7,9 +7,10 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '..
|
|
|
7
7
|
* @param schema - The schema for which retrieving a schema is desired
|
|
8
8
|
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
9
9
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
10
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
10
11
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
11
12
|
*/
|
|
12
|
-
export default function retrieveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, rawFormData?: T): S;
|
|
13
|
+
export default function retrieveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, rawFormData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S;
|
|
13
14
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
14
15
|
* with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
|
|
15
16
|
* conditions will be returned.
|
|
@@ -21,9 +22,10 @@ export default function retrieveSchema<T = any, S extends StrictRJSFSchema = RJS
|
|
|
21
22
|
* dependencies as a list of schemas
|
|
22
23
|
* @param recurseList - The list of recursive references already processed
|
|
23
24
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
25
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
24
26
|
* @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
|
|
25
27
|
*/
|
|
26
|
-
export declare function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
28
|
+
export declare function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
27
29
|
/** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
|
|
28
30
|
* `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
|
|
29
31
|
* From those lists, build a matrix for each `xxxOf` where there is more than one schema for a row in the list of lists.
|
|
@@ -39,6 +41,13 @@ export declare function resolveCondition<T = any, S extends StrictRJSFSchema = R
|
|
|
39
41
|
* @returns - The list of all permutations of schemas for a set of `xxxOf`s
|
|
40
42
|
*/
|
|
41
43
|
export declare function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchema>(listOfLists: S[][]): S[][];
|
|
44
|
+
/** Returns the subset of 'patternProperties' specifications that match the given 'key'
|
|
45
|
+
*
|
|
46
|
+
* @param schema - The schema whose 'patternProperties' are to be filtered
|
|
47
|
+
* @param key - The key to match against the 'patternProperties' specifications
|
|
48
|
+
* @returns - The subset of 'patternProperties' specifications that match the given 'key'
|
|
49
|
+
*/
|
|
50
|
+
export declare function getMatchingPatternProperties<S extends StrictRJSFSchema = RJSFSchema>(schema: S, key: string): Required<S['patternProperties']>;
|
|
42
51
|
/** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
|
|
43
52
|
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
|
|
44
53
|
* `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
|
|
@@ -50,9 +59,10 @@ export declare function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = R
|
|
|
50
59
|
* as a list of schemas
|
|
51
60
|
* @param recurseList - The list of recursive references already processed
|
|
52
61
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
62
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
53
63
|
* @returns - The list of schemas having its references, dependencies and allOf schemas resolved
|
|
54
64
|
*/
|
|
55
|
-
export declare function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
65
|
+
export declare function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
56
66
|
/** Resolves all references within a schema and then returns the `retrieveSchemaInternal()` if the resolved schema is
|
|
57
67
|
* actually different than the original. Passes the `expandAllBranches` flag down to the `retrieveSchemaInternal()`
|
|
58
68
|
* helper call.
|
|
@@ -64,26 +74,29 @@ export declare function resolveSchema<T = any, S extends StrictRJSFSchema = RJSF
|
|
|
64
74
|
* as a list of schemas
|
|
65
75
|
* @param recurseList - The list of recursive references already processed
|
|
66
76
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
77
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
67
78
|
* @returns - The list schemas retrieved after having all references resolved
|
|
68
79
|
*/
|
|
69
|
-
export declare function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
80
|
+
export declare function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
70
81
|
/** Resolves all references within the schema itself as well as any of its properties and array items.
|
|
71
82
|
*
|
|
72
83
|
* @param schema - The schema for which resolving all references is desired
|
|
73
84
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
74
85
|
* @param recurseList - List of $refs already resolved to prevent recursion
|
|
86
|
+
* @param [baseURI] - The base URI to be used for resolving relative references
|
|
75
87
|
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved
|
|
76
88
|
*/
|
|
77
|
-
export declare function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S, recurseList: string[]): S;
|
|
89
|
+
export declare function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S, recurseList: string[], baseURI?: string): S;
|
|
78
90
|
/** Creates new 'properties' items for each key in the `formData`
|
|
79
91
|
*
|
|
80
92
|
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
81
93
|
* @param theSchema - The schema for which the existing additional properties is desired
|
|
82
94
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
|
|
83
95
|
* @param [aFormData] - The current formData, if any, to assist retrieving a schema
|
|
96
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
84
97
|
* @returns - The updated schema with additional properties stubbed
|
|
85
98
|
*/
|
|
86
|
-
export declare function stubExistingAdditionalProperties<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, rootSchema?: S, aFormData?: T): S;
|
|
99
|
+
export declare function stubExistingAdditionalProperties<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, rootSchema?: S, aFormData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S;
|
|
87
100
|
/** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties,
|
|
88
101
|
* references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData`
|
|
89
102
|
* that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches
|
|
@@ -96,10 +109,11 @@ export declare function stubExistingAdditionalProperties<T = any, S extends Stri
|
|
|
96
109
|
* @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
|
|
97
110
|
* dependencies as a list of schemas
|
|
98
111
|
* @param [recurseList=[]] - The optional, list of recursive references already processed
|
|
112
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
99
113
|
* @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
|
|
100
114
|
* resolved. Multiple schemas may be returned if `expandAllBranches` is true.
|
|
101
115
|
*/
|
|
102
|
-
export declare function retrieveSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, rawFormData?: T, expandAllBranches?: boolean, recurseList?: string[]): S[];
|
|
116
|
+
export declare function retrieveSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, rawFormData?: T, expandAllBranches?: boolean, recurseList?: string[], experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
103
117
|
/** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from
|
|
104
118
|
* `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL
|
|
105
119
|
* options are retrieved and returned.
|
|
@@ -123,9 +137,10 @@ export declare function resolveAnyOrOneOfSchemas<T = any, S extends StrictRJSFSc
|
|
|
123
137
|
* as a list of schemas
|
|
124
138
|
* @param recurseList - The list of recursive references already processed
|
|
125
139
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
140
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
126
141
|
* @returns - The list of schemas with their dependencies resolved
|
|
127
142
|
*/
|
|
128
|
-
export declare function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
143
|
+
export declare function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
129
144
|
/** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
|
|
130
145
|
* `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
|
|
131
146
|
*
|
|
@@ -137,9 +152,10 @@ export declare function resolveDependencies<T = any, S extends StrictRJSFSchema
|
|
|
137
152
|
* as a list of schemas
|
|
138
153
|
* @param recurseList - The list of recursive references already processed
|
|
139
154
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
155
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
140
156
|
* @returns - The schema with the `dependencies` resolved into it
|
|
141
157
|
*/
|
|
142
|
-
export declare function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, dependencies: S['dependencies'], resolvedSchema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
158
|
+
export declare function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, dependencies: S['dependencies'], resolvedSchema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
143
159
|
/** Updates a schema with additionally required properties added
|
|
144
160
|
*
|
|
145
161
|
* @param schema - The schema for which resolving a dependent properties is desired
|
|
@@ -159,9 +175,10 @@ export declare function withDependentProperties<S extends StrictRJSFSchema = RJS
|
|
|
159
175
|
* as a list of schemas
|
|
160
176
|
* @param recurseList - The list of recursive references already processed
|
|
161
177
|
* @param [formData]- The current formData to assist retrieving a schema
|
|
178
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
162
179
|
* @returns - The list of schemas with the dependent schema resolved into them
|
|
163
180
|
*/
|
|
164
|
-
export declare function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, dependencyValue: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
181
|
+
export declare function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, dependencyValue: S, expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
165
182
|
/** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
|
|
166
183
|
* true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to
|
|
167
184
|
* the `retrieveSchemaInternal()` helper call.
|
|
@@ -175,6 +192,7 @@ export declare function withDependentSchema<T = any, S extends StrictRJSFSchema
|
|
|
175
192
|
* as a list of schemas
|
|
176
193
|
* @param recurseList - The list of recursive references already processed
|
|
177
194
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
195
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
178
196
|
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
179
197
|
*/
|
|
180
|
-
export declare function withExactlyOneSubschema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, oneOf: S['oneOf'], expandAllBranches: boolean, recurseList: string[], formData?: T): S[];
|
|
198
|
+
export declare function withExactlyOneSubschema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, oneOf: S['oneOf'], expandAllBranches: boolean, recurseList: string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): S[];
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import uniq from 'lodash/uniq';
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import set from 'lodash-es/set.js';
|
|
3
|
+
import times from 'lodash-es/times.js';
|
|
4
|
+
import transform from 'lodash-es/transform.js';
|
|
5
|
+
import merge from 'lodash-es/merge.js';
|
|
6
|
+
import flattenDeep from 'lodash-es/flattenDeep.js';
|
|
7
|
+
import uniq from 'lodash-es/uniq.js';
|
|
9
8
|
import mergeAllOf from 'json-schema-merge-allof';
|
|
10
|
-
import { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, DEPENDENCIES_KEY, IF_KEY, ONE_OF_KEY,
|
|
11
|
-
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition';
|
|
12
|
-
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
13
|
-
import guessType from '../guessType';
|
|
14
|
-
import isObject from '../isObject';
|
|
15
|
-
import mergeSchemas from '../mergeSchemas';
|
|
16
|
-
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
9
|
+
import { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, DEPENDENCIES_KEY, ID_KEY, IF_KEY, ITEMS_KEY, ONE_OF_KEY, PATTERN_PROPERTIES_KEY, PROPERTIES_KEY, REF_KEY, } from '../constants.js';
|
|
10
|
+
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition.js';
|
|
11
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.js';
|
|
12
|
+
import guessType from '../guessType.js';
|
|
13
|
+
import isObject from '../isObject.js';
|
|
14
|
+
import mergeSchemas from '../mergeSchemas.js';
|
|
15
|
+
import getFirstMatchingOption from './getFirstMatchingOption.js';
|
|
16
|
+
import deepEquals from '../deepEquals.js';
|
|
17
|
+
import isEmpty from 'lodash-es/isEmpty.js';
|
|
17
18
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
18
19
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
19
20
|
* potentially recursive resolution.
|
|
@@ -22,10 +23,11 @@ import getFirstMatchingOption from './getFirstMatchingOption';
|
|
|
22
23
|
* @param schema - The schema for which retrieving a schema is desired
|
|
23
24
|
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
24
25
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
26
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
25
27
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
26
28
|
*/
|
|
27
|
-
export default function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
28
|
-
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
29
|
+
export default function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
30
|
+
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, undefined, undefined, experimental_customMergeAllOf)[0];
|
|
29
31
|
}
|
|
30
32
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
31
33
|
* with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
|
|
@@ -38,31 +40,32 @@ export default function retrieveSchema(validator, schema, rootSchema = {}, rawFo
|
|
|
38
40
|
* dependencies as a list of schemas
|
|
39
41
|
* @param recurseList - The list of recursive references already processed
|
|
40
42
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
43
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
41
44
|
* @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
|
|
42
45
|
*/
|
|
43
|
-
export function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
46
|
+
export function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
44
47
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
45
48
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
46
49
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
47
50
|
let schemas = [];
|
|
48
51
|
if (expandAllBranches) {
|
|
49
52
|
if (then && typeof then !== 'boolean') {
|
|
50
|
-
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList));
|
|
53
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf));
|
|
51
54
|
}
|
|
52
55
|
if (otherwise && typeof otherwise !== 'boolean') {
|
|
53
|
-
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList));
|
|
56
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf));
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
60
|
const conditionalSchema = conditionValue ? then : otherwise;
|
|
58
61
|
if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
|
|
59
|
-
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches, recurseList));
|
|
62
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf));
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
if (schemas.length) {
|
|
63
66
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
64
67
|
}
|
|
65
|
-
return resolvedSchemas.flatMap((s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList));
|
|
68
|
+
return resolvedSchemas.flatMap((s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf));
|
|
66
69
|
}
|
|
67
70
|
/** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
|
|
68
71
|
* `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
|
|
@@ -87,10 +90,24 @@ export function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
87
90
|
// Otherwise just push in the single value into the current set of permutations
|
|
88
91
|
permutations.forEach((permutation) => permutation.push(list[0]));
|
|
89
92
|
return permutations;
|
|
90
|
-
}, [[]]
|
|
91
|
-
);
|
|
93
|
+
}, [[]]);
|
|
92
94
|
return allPermutations;
|
|
93
95
|
}
|
|
96
|
+
/** Returns the subset of 'patternProperties' specifications that match the given 'key'
|
|
97
|
+
*
|
|
98
|
+
* @param schema - The schema whose 'patternProperties' are to be filtered
|
|
99
|
+
* @param key - The key to match against the 'patternProperties' specifications
|
|
100
|
+
* @returns - The subset of 'patternProperties' specifications that match the given 'key'
|
|
101
|
+
*/
|
|
102
|
+
export function getMatchingPatternProperties(schema, key) {
|
|
103
|
+
return Object.keys(schema.patternProperties)
|
|
104
|
+
.filter((pattern) => RegExp(pattern).test(key))
|
|
105
|
+
.reduce((obj, pattern) => {
|
|
106
|
+
// Pass the pattern using the `[]` index notation so that any `.` in the pattern are not used as a dotted path
|
|
107
|
+
set(obj, [pattern], schema.patternProperties[pattern]);
|
|
108
|
+
return obj;
|
|
109
|
+
}, {});
|
|
110
|
+
}
|
|
94
111
|
/** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
|
|
95
112
|
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
|
|
96
113
|
* `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
|
|
@@ -102,9 +119,10 @@ export function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
102
119
|
* as a list of schemas
|
|
103
120
|
* @param recurseList - The list of recursive references already processed
|
|
104
121
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
122
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
105
123
|
* @returns - The list of schemas having its references, dependencies and allOf schemas resolved
|
|
106
124
|
*/
|
|
107
|
-
export function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
125
|
+
export function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
108
126
|
const updatedSchemas = resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData);
|
|
109
127
|
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
110
128
|
// return the updatedSchemas array if it has either multiple schemas within it
|
|
@@ -114,13 +132,16 @@ export function resolveSchema(validator, schema, rootSchema, expandAllBranches,
|
|
|
114
132
|
if (DEPENDENCIES_KEY in schema) {
|
|
115
133
|
const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData);
|
|
116
134
|
return resolvedSchemas.flatMap((s) => {
|
|
117
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList);
|
|
135
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf);
|
|
118
136
|
});
|
|
119
137
|
}
|
|
120
138
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
121
|
-
const allOfSchemaElements = schema.allOf.map((allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches, recurseList));
|
|
139
|
+
const allOfSchemaElements = schema.allOf.map((allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf));
|
|
122
140
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
123
|
-
return allPermutations.map((permutation) => ({
|
|
141
|
+
return allPermutations.map((permutation) => ({
|
|
142
|
+
...schema,
|
|
143
|
+
allOf: permutation,
|
|
144
|
+
}));
|
|
124
145
|
}
|
|
125
146
|
// No $ref or dependencies or allOf attribute was found, returning the original schema.
|
|
126
147
|
return [schema];
|
|
@@ -136,13 +157,14 @@ export function resolveSchema(validator, schema, rootSchema, expandAllBranches,
|
|
|
136
157
|
* as a list of schemas
|
|
137
158
|
* @param recurseList - The list of recursive references already processed
|
|
138
159
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
160
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
139
161
|
* @returns - The list schemas retrieved after having all references resolved
|
|
140
162
|
*/
|
|
141
|
-
export function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
163
|
+
export function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
142
164
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
143
165
|
if (updatedSchema !== schema) {
|
|
144
166
|
// Only call this if the schema was actually changed by the `resolveAllReferences()` function
|
|
145
|
-
return retrieveSchemaInternal(validator, updatedSchema, rootSchema, formData, expandAllBranches, recurseList);
|
|
167
|
+
return retrieveSchemaInternal(validator, updatedSchema, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf);
|
|
146
168
|
}
|
|
147
169
|
return [schema];
|
|
148
170
|
}
|
|
@@ -151,9 +173,10 @@ export function resolveReference(validator, schema, rootSchema, expandAllBranche
|
|
|
151
173
|
* @param schema - The schema for which resolving all references is desired
|
|
152
174
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
153
175
|
* @param recurseList - List of $refs already resolved to prevent recursion
|
|
176
|
+
* @param [baseURI] - The base URI to be used for resolving relative references
|
|
154
177
|
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved
|
|
155
178
|
*/
|
|
156
|
-
export function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
179
|
+
export function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
157
180
|
if (!isObject(schema)) {
|
|
158
181
|
return schema;
|
|
159
182
|
}
|
|
@@ -167,14 +190,17 @@ export function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
167
190
|
}
|
|
168
191
|
recurseList.push($ref);
|
|
169
192
|
// Retrieve the referenced schema definition.
|
|
170
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
193
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
171
194
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
195
|
+
if (ID_KEY in resolvedSchema) {
|
|
196
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
197
|
+
}
|
|
172
198
|
}
|
|
173
199
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
174
200
|
const childrenLists = [];
|
|
175
201
|
const updatedProps = transform(resolvedSchema[PROPERTIES_KEY], (result, value, key) => {
|
|
176
202
|
const childList = [...recurseList];
|
|
177
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
203
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
178
204
|
childrenLists.push(childList);
|
|
179
205
|
}, {});
|
|
180
206
|
merge(recurseList, uniq(flattenDeep(childrenLists)));
|
|
@@ -185,10 +211,10 @@ export function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
185
211
|
typeof resolvedSchema.items !== 'boolean') {
|
|
186
212
|
resolvedSchema = {
|
|
187
213
|
...resolvedSchema,
|
|
188
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList),
|
|
214
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI),
|
|
189
215
|
};
|
|
190
216
|
}
|
|
191
|
-
return
|
|
217
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
192
218
|
}
|
|
193
219
|
/** Creates new 'properties' items for each key in the `formData`
|
|
194
220
|
*
|
|
@@ -196,9 +222,10 @@ export function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
196
222
|
* @param theSchema - The schema for which the existing additional properties is desired
|
|
197
223
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
|
|
198
224
|
* @param [aFormData] - The current formData, if any, to assist retrieving a schema
|
|
225
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
199
226
|
* @returns - The updated schema with additional properties stubbed
|
|
200
227
|
*/
|
|
201
|
-
export function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
228
|
+
export function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
202
229
|
// Clone the schema so that we don't ruin the consumer's original
|
|
203
230
|
const schema = {
|
|
204
231
|
...theSchema,
|
|
@@ -211,31 +238,47 @@ export function stubExistingAdditionalProperties(validator, theSchema, rootSchem
|
|
|
211
238
|
// No need to stub, our schema already has the property
|
|
212
239
|
return;
|
|
213
240
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
241
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
242
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
243
|
+
if (!isEmpty(matchingProperties)) {
|
|
244
|
+
schema.properties[key] = retrieveSchema(validator, { allOf: Object.values(matchingProperties) }, rootSchema, get(formData, [key]), experimental_customMergeAllOf);
|
|
245
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
246
|
+
return;
|
|
218
247
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
additionalProperties
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
248
|
+
}
|
|
249
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
250
|
+
let additionalProperties = {};
|
|
251
|
+
if (typeof schema.additionalProperties !== 'boolean') {
|
|
252
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
253
|
+
additionalProperties = retrieveSchema(validator, { $ref: get(schema.additionalProperties, [REF_KEY]) }, rootSchema, formData, experimental_customMergeAllOf);
|
|
254
|
+
}
|
|
255
|
+
else if ('type' in schema.additionalProperties) {
|
|
256
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
257
|
+
}
|
|
258
|
+
else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
259
|
+
additionalProperties = {
|
|
260
|
+
type: 'object',
|
|
261
|
+
...schema.additionalProperties,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
266
|
+
}
|
|
227
267
|
}
|
|
228
268
|
else {
|
|
229
269
|
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
230
270
|
}
|
|
271
|
+
// The type of our new key should match the additionalProperties value;
|
|
272
|
+
schema.properties[key] = additionalProperties;
|
|
273
|
+
// Set our additional property flag so we know it was dynamically added
|
|
274
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
231
275
|
}
|
|
232
276
|
else {
|
|
233
|
-
|
|
277
|
+
// Invalid property
|
|
278
|
+
schema.properties[key] = { type: 'null' };
|
|
279
|
+
// Set our additional property flag so we know it was dynamically added
|
|
280
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
234
281
|
}
|
|
235
|
-
// The type of our new key should match the additionalProperties value;
|
|
236
|
-
schema.properties[key] = additionalProperties;
|
|
237
|
-
// Set our additional property flag so we know it was dynamically added
|
|
238
|
-
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
239
282
|
});
|
|
240
283
|
return schema;
|
|
241
284
|
}
|
|
@@ -251,18 +294,20 @@ export function stubExistingAdditionalProperties(validator, theSchema, rootSchem
|
|
|
251
294
|
* @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
|
|
252
295
|
* dependencies as a list of schemas
|
|
253
296
|
* @param [recurseList=[]] - The optional, list of recursive references already processed
|
|
297
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
254
298
|
* @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
|
|
255
299
|
* resolved. Multiple schemas may be returned if `expandAllBranches` is true.
|
|
256
300
|
*/
|
|
257
|
-
export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
301
|
+
export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
258
302
|
if (!isObject(schema)) {
|
|
259
303
|
return [{}];
|
|
260
304
|
}
|
|
261
|
-
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData);
|
|
305
|
+
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData, experimental_customMergeAllOf);
|
|
262
306
|
return resolvedSchemas.flatMap((s) => {
|
|
307
|
+
var _a;
|
|
263
308
|
let resolvedSchema = s;
|
|
264
309
|
if (IF_KEY in resolvedSchema) {
|
|
265
|
-
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, recurseList, rawFormData);
|
|
310
|
+
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, recurseList, rawFormData, experimental_customMergeAllOf);
|
|
266
311
|
}
|
|
267
312
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
268
313
|
// resolve allOf schemas
|
|
@@ -271,9 +316,30 @@ export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormDat
|
|
|
271
316
|
return [...allOf, restOfSchema];
|
|
272
317
|
}
|
|
273
318
|
try {
|
|
274
|
-
|
|
275
|
-
|
|
319
|
+
const withContainsSchemas = [];
|
|
320
|
+
const withoutContainsSchemas = [];
|
|
321
|
+
(_a = resolvedSchema.allOf) === null || _a === void 0 ? void 0 : _a.forEach((s) => {
|
|
322
|
+
if (typeof s === 'object' && s.contains) {
|
|
323
|
+
withContainsSchemas.push(s);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
withoutContainsSchemas.push(s);
|
|
327
|
+
}
|
|
276
328
|
});
|
|
329
|
+
if (withContainsSchemas.length) {
|
|
330
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
331
|
+
}
|
|
332
|
+
resolvedSchema = experimental_customMergeAllOf
|
|
333
|
+
? experimental_customMergeAllOf(resolvedSchema)
|
|
334
|
+
: mergeAllOf(resolvedSchema, {
|
|
335
|
+
deep: false,
|
|
336
|
+
resolvers: {
|
|
337
|
+
$defs: mergeAllOf.options.resolvers.definitions,
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
if (withContainsSchemas.length) {
|
|
341
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
342
|
+
}
|
|
277
343
|
}
|
|
278
344
|
catch (e) {
|
|
279
345
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
@@ -281,9 +347,22 @@ export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormDat
|
|
|
281
347
|
return resolvedSchemaWithoutAllOf;
|
|
282
348
|
}
|
|
283
349
|
}
|
|
284
|
-
|
|
350
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
351
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce((schema, key) => {
|
|
352
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
353
|
+
if (!isEmpty(matchingProperties)) {
|
|
354
|
+
schema.properties[key] = retrieveSchema(validator, { allOf: [schema.properties[key], ...Object.values(matchingProperties)] }, rootSchema, get(rawFormData, [key]), experimental_customMergeAllOf);
|
|
355
|
+
}
|
|
356
|
+
return schema;
|
|
357
|
+
}, {
|
|
358
|
+
...resolvedSchema,
|
|
359
|
+
properties: { ...resolvedSchema.properties },
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema ||
|
|
363
|
+
(ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false);
|
|
285
364
|
if (hasAdditionalProperties) {
|
|
286
|
-
return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
|
|
365
|
+
return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData, experimental_customMergeAllOf);
|
|
287
366
|
}
|
|
288
367
|
return resolvedSchema;
|
|
289
368
|
});
|
|
@@ -337,13 +416,14 @@ export function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAl
|
|
|
337
416
|
* as a list of schemas
|
|
338
417
|
* @param recurseList - The list of recursive references already processed
|
|
339
418
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
419
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
340
420
|
* @returns - The list of schemas with their dependencies resolved
|
|
341
421
|
*/
|
|
342
|
-
export function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
422
|
+
export function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
343
423
|
// Drop the dependencies from the source schema.
|
|
344
424
|
const { dependencies, ...remainingSchema } = schema;
|
|
345
425
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
|
|
346
|
-
return resolvedSchemas.flatMap((resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData));
|
|
426
|
+
return resolvedSchemas.flatMap((resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf));
|
|
347
427
|
}
|
|
348
428
|
/** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
|
|
349
429
|
* `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
|
|
@@ -356,9 +436,10 @@ export function resolveDependencies(validator, schema, rootSchema, expandAllBran
|
|
|
356
436
|
* as a list of schemas
|
|
357
437
|
* @param recurseList - The list of recursive references already processed
|
|
358
438
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
439
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
359
440
|
* @returns - The schema with the `dependencies` resolved into it
|
|
360
441
|
*/
|
|
361
|
-
export function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
442
|
+
export function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
362
443
|
let schemas = [resolvedSchema];
|
|
363
444
|
// Process dependencies updating the local schema properties as appropriate.
|
|
364
445
|
for (const dependencyKey in dependencies) {
|
|
@@ -375,9 +456,9 @@ export function processDependencies(validator, dependencies, resolvedSchema, roo
|
|
|
375
456
|
schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
|
|
376
457
|
}
|
|
377
458
|
else if (isObject(dependencyValue)) {
|
|
378
|
-
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData);
|
|
459
|
+
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf);
|
|
379
460
|
}
|
|
380
|
-
return schemas.flatMap((schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, recurseList, formData));
|
|
461
|
+
return schemas.flatMap((schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf));
|
|
381
462
|
}
|
|
382
463
|
return schemas;
|
|
383
464
|
}
|
|
@@ -408,10 +489,11 @@ export function withDependentProperties(schema, additionallyRequired) {
|
|
|
408
489
|
* as a list of schemas
|
|
409
490
|
* @param recurseList - The list of recursive references already processed
|
|
410
491
|
* @param [formData]- The current formData to assist retrieving a schema
|
|
492
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
411
493
|
* @returns - The list of schemas with the dependent schema resolved into them
|
|
412
494
|
*/
|
|
413
|
-
export function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
414
|
-
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches, recurseList);
|
|
495
|
+
export function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
496
|
+
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf);
|
|
415
497
|
return dependentSchemas.flatMap((dependent) => {
|
|
416
498
|
const { oneOf, ...dependentSchema } = dependent;
|
|
417
499
|
schema = mergeSchemas(schema, dependentSchema);
|
|
@@ -427,7 +509,7 @@ export function withDependentSchema(validator, schema, rootSchema, dependencyKey
|
|
|
427
509
|
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
428
510
|
});
|
|
429
511
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
430
|
-
return allPermutations.flatMap((resolvedOneOf) => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, recurseList, formData));
|
|
512
|
+
return allPermutations.flatMap((resolvedOneOf) => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf));
|
|
431
513
|
});
|
|
432
514
|
}
|
|
433
515
|
/** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
|
|
@@ -443,9 +525,10 @@ export function withDependentSchema(validator, schema, rootSchema, dependencyKey
|
|
|
443
525
|
* as a list of schemas
|
|
444
526
|
* @param recurseList - The list of recursive references already processed
|
|
445
527
|
* @param [formData] - The current formData to assist retrieving a schema
|
|
528
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
446
529
|
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
447
530
|
*/
|
|
448
|
-
export function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
531
|
+
export function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
449
532
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
450
533
|
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
451
534
|
return false;
|
|
@@ -470,7 +553,7 @@ export function withExactlyOneSubschema(validator, schema, rootSchema, dependenc
|
|
|
470
553
|
const subschema = s;
|
|
471
554
|
const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
|
|
472
555
|
const dependentSchema = { ...subschema, properties: dependentSubschema };
|
|
473
|
-
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches, recurseList);
|
|
556
|
+
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches, recurseList, experimental_customMergeAllOf);
|
|
474
557
|
return schemas.map((s) => mergeSchemas(schema, s));
|
|
475
558
|
});
|
|
476
559
|
}
|