@ng-formworks/core 17.2.7 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +836 -0
- package/esm2022/lib/framework-library/framework-library.service.mjs +175 -0
- package/esm2022/lib/framework-library/framework.mjs +15 -0
- package/esm2022/lib/framework-library/no-framework.component.mjs +18 -0
- package/esm2022/lib/framework-library/no-framework.module.mjs +27 -0
- package/esm2022/lib/framework-library/no.framework.mjs +19 -0
- package/esm2022/lib/json-schema-form.component.mjs +765 -0
- package/esm2022/lib/json-schema-form.module.mjs +26 -0
- package/esm2022/lib/json-schema-form.service.mjs +679 -0
- package/esm2022/lib/locale/de-validation-messages.mjs +60 -0
- package/esm2022/lib/locale/en-validation-messages.mjs +60 -0
- package/esm2022/lib/locale/es-validation-messages.mjs +57 -0
- package/esm2022/lib/locale/fr-validation-messages.mjs +60 -0
- package/esm2022/lib/locale/index.mjs +8 -0
- package/esm2022/lib/locale/it-validation-messages.mjs +60 -0
- package/esm2022/lib/locale/pt-validation-messages.mjs +60 -0
- package/esm2022/lib/locale/zh-validation-messages.mjs +60 -0
- package/esm2022/lib/shared/convert-schema-to-draft6.function.mjs +300 -0
- package/esm2022/lib/shared/form-group.functions.mjs +442 -0
- package/esm2022/lib/shared/format-regex.constants.mjs +54 -0
- package/esm2022/lib/shared/index.mjs +12 -0
- package/esm2022/lib/shared/json-schema.functions.mjs +784 -0
- package/esm2022/lib/shared/json.validators.mjs +884 -0
- package/esm2022/lib/shared/jsonpointer.functions.mjs +1026 -0
- package/esm2022/lib/shared/layout.functions.mjs +1154 -0
- package/esm2022/lib/shared/merge-schemas.function.mjs +345 -0
- package/esm2022/lib/shared/utility.functions.mjs +380 -0
- package/esm2022/lib/shared/validator.functions.mjs +584 -0
- package/esm2022/lib/widget-library/add-reference.component.mjs +61 -0
- package/esm2022/lib/widget-library/button.component.mjs +72 -0
- package/esm2022/lib/widget-library/checkbox.component.mjs +105 -0
- package/esm2022/lib/widget-library/checkboxes.component.mjs +147 -0
- package/esm2022/lib/widget-library/file.component.mjs +35 -0
- package/esm2022/lib/widget-library/hidden.component.mjs +54 -0
- package/esm2022/lib/widget-library/index.mjs +55 -0
- package/esm2022/lib/widget-library/input.component.mjs +119 -0
- package/esm2022/lib/widget-library/message.component.mjs +38 -0
- package/esm2022/lib/widget-library/none.component.mjs +21 -0
- package/esm2022/lib/widget-library/number.component.mjs +123 -0
- package/esm2022/lib/widget-library/one-of.component.mjs +35 -0
- package/esm2022/lib/widget-library/orderable.directive.mjs +123 -0
- package/esm2022/lib/widget-library/radios.component.mjs +153 -0
- package/esm2022/lib/widget-library/root.component.mjs +79 -0
- package/esm2022/lib/widget-library/section.component.mjs +199 -0
- package/esm2022/lib/widget-library/select-framework.component.mjs +51 -0
- package/esm2022/lib/widget-library/select-widget.component.mjs +46 -0
- package/esm2022/lib/widget-library/select.component.mjs +150 -0
- package/esm2022/lib/widget-library/submit.component.mjs +82 -0
- package/esm2022/lib/widget-library/tab.component.mjs +41 -0
- package/esm2022/lib/widget-library/tabs.component.mjs +108 -0
- package/esm2022/lib/widget-library/template.component.mjs +46 -0
- package/esm2022/lib/widget-library/textarea.component.mjs +104 -0
- package/esm2022/lib/widget-library/widget-library.module.mjs +42 -0
- package/esm2022/lib/widget-library/widget-library.service.mjs +226 -0
- package/esm2022/ng-formworks-core.mjs +5 -0
- package/esm2022/public_api.mjs +13 -0
- package/fesm2022/ng-formworks-core.mjs +10149 -0
- package/fesm2022/ng-formworks-core.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/framework-library/framework-library.service.d.ts +55 -0
- package/lib/framework-library/framework.d.ts +13 -0
- package/lib/framework-library/no-framework.component.d.ts +8 -0
- package/lib/framework-library/no-framework.module.d.ts +9 -0
- package/lib/framework-library/no.framework.d.ts +10 -0
- package/lib/json-schema-form.component.d.ts +218 -0
- package/lib/json-schema-form.module.d.ts +11 -0
- package/lib/json-schema-form.service.d.ts +115 -0
- package/lib/locale/de-validation-messages.d.ts +1 -0
- package/lib/locale/en-validation-messages.d.ts +1 -0
- package/lib/locale/es-validation-messages.d.ts +1 -0
- package/lib/locale/fr-validation-messages.d.ts +1 -0
- package/{src/lib/locale/index.ts → lib/locale/index.d.ts} +7 -7
- package/lib/locale/it-validation-messages.d.ts +1 -0
- package/lib/locale/pt-validation-messages.d.ts +1 -0
- package/lib/locale/zh-validation-messages.d.ts +1 -0
- package/lib/shared/convert-schema-to-draft6.function.d.ts +21 -0
- package/lib/shared/form-group.functions.d.ts +100 -0
- package/lib/shared/format-regex.constants.d.ts +19 -0
- package/lib/shared/index.d.ts +9 -0
- package/lib/shared/json-schema.functions.d.ts +193 -0
- package/lib/shared/json.validators.d.ts +441 -0
- package/lib/shared/jsonpointer.functions.d.ts +416 -0
- package/lib/shared/layout.functions.d.ts +83 -0
- package/lib/shared/merge-schemas.function.d.ts +19 -0
- package/lib/shared/utility.functions.d.ts +165 -0
- package/{src/lib/shared/validator.functions.ts → lib/shared/validator.functions.d.ts} +364 -601
- package/lib/widget-library/add-reference.component.d.ts +20 -0
- package/lib/widget-library/button.component.d.ts +21 -0
- package/lib/widget-library/checkbox.component.d.ts +24 -0
- package/lib/widget-library/checkboxes.component.d.ts +24 -0
- package/lib/widget-library/file.component.d.ts +21 -0
- package/lib/widget-library/hidden.component.d.ts +19 -0
- package/{src/lib/widget-library/index.ts → lib/widget-library/index.d.ts} +47 -56
- package/lib/widget-library/input.component.d.ts +22 -0
- package/lib/widget-library/message.component.d.ts +15 -0
- package/lib/widget-library/none.component.d.ts +8 -0
- package/lib/widget-library/number.component.d.ts +25 -0
- package/lib/widget-library/one-of.component.d.ts +21 -0
- package/lib/widget-library/orderable.directive.d.ts +41 -0
- package/lib/widget-library/radios.component.d.ts +23 -0
- package/lib/widget-library/root.component.d.ts +17 -0
- package/lib/widget-library/section.component.d.ts +19 -0
- package/lib/widget-library/select-framework.component.d.ts +18 -0
- package/lib/widget-library/select-widget.component.d.ts +18 -0
- package/lib/widget-library/select.component.d.ts +24 -0
- package/lib/widget-library/submit.component.d.ts +24 -0
- package/lib/widget-library/tab.component.d.ts +14 -0
- package/lib/widget-library/tabs.component.d.ts +20 -0
- package/lib/widget-library/template.component.d.ts +18 -0
- package/lib/widget-library/textarea.component.d.ts +21 -0
- package/lib/widget-library/widget-library.module.d.ts +31 -0
- package/lib/widget-library/widget-library.service.d.ts +22 -0
- package/package.json +64 -53
- package/{src/public_api.ts → public_api.d.ts} +9 -21
- package/karma.conf.js +0 -46
- package/ng-package.json +0 -11
- package/src/lib/framework-library/framework-library.service.ts +0 -195
- package/src/lib/framework-library/framework.ts +0 -11
- package/src/lib/framework-library/no-framework.component.html +0 -2
- package/src/lib/framework-library/no-framework.component.ts +0 -11
- package/src/lib/framework-library/no-framework.module.ts +0 -18
- package/src/lib/framework-library/no.framework.ts +0 -11
- package/src/lib/json-schema-form.component.html +0 -7
- package/src/lib/json-schema-form.component.ts +0 -809
- package/src/lib/json-schema-form.module.ts +0 -17
- package/src/lib/json-schema-form.service.ts +0 -907
- package/src/lib/locale/de-validation-messages.ts +0 -58
- package/src/lib/locale/en-validation-messages.ts +0 -58
- package/src/lib/locale/es-validation-messages.ts +0 -55
- package/src/lib/locale/fr-validation-messages.ts +0 -58
- package/src/lib/locale/it-validation-messages.ts +0 -58
- package/src/lib/locale/pt-validation-messages.ts +0 -58
- package/src/lib/locale/zh-validation-messages.ts +0 -58
- package/src/lib/locale-dates/en-US.ts +0 -5
- package/src/lib/shared/convert-schema-to-draft6.function.ts +0 -321
- package/src/lib/shared/form-group.functions.ts +0 -522
- package/src/lib/shared/format-regex.constants.ts +0 -73
- package/src/lib/shared/index.ts +0 -40
- package/src/lib/shared/json-schema.functions.ts +0 -788
- package/src/lib/shared/json.validators.ts +0 -878
- package/src/lib/shared/jsonpointer.functions.ts +0 -1012
- package/src/lib/shared/jspointer.functions.json.spec.ts +0 -103
- package/src/lib/shared/layout.functions.ts +0 -1233
- package/src/lib/shared/merge-schemas.function.ts +0 -329
- package/src/lib/shared/utility.functions.ts +0 -373
- package/src/lib/shared/validator.functions.spec.ts +0 -55
- package/src/lib/widget-library/add-reference.component.ts +0 -59
- package/src/lib/widget-library/button.component.ts +0 -54
- package/src/lib/widget-library/checkbox.component.ts +0 -74
- package/src/lib/widget-library/checkboxes.component.ts +0 -104
- package/src/lib/widget-library/file.component.ts +0 -36
- package/src/lib/widget-library/hidden.component.ts +0 -39
- package/src/lib/widget-library/input.component.ts +0 -76
- package/src/lib/widget-library/message.component.ts +0 -29
- package/src/lib/widget-library/none.component.ts +0 -12
- package/src/lib/widget-library/number.component.ts +0 -79
- package/src/lib/widget-library/one-of.component.ts +0 -36
- package/src/lib/widget-library/orderable.directive.ts +0 -130
- package/src/lib/widget-library/radios.component.ts +0 -101
- package/src/lib/widget-library/root.component.ts +0 -78
- package/src/lib/widget-library/section.component.ts +0 -133
- package/src/lib/widget-library/select-framework.component.ts +0 -50
- package/src/lib/widget-library/select-widget.component.ts +0 -46
- package/src/lib/widget-library/select.component.ts +0 -96
- package/src/lib/widget-library/submit.component.ts +0 -68
- package/src/lib/widget-library/tab.component.ts +0 -29
- package/src/lib/widget-library/tabs.component.ts +0 -83
- package/src/lib/widget-library/template.component.ts +0 -52
- package/src/lib/widget-library/textarea.component.ts +0 -68
- package/src/lib/widget-library/widget-library.module.ts +0 -13
- package/src/lib/widget-library/widget-library.service.ts +0 -234
- package/src/test.ts +0 -18
- package/tsconfig.lib.json +0 -25
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -17
- package/tslint.json +0 -11
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
import isEqual from 'lodash/isEqual';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isArray, isEmpty, isNumber, isObject, isString
|
|
5
|
-
} from './validator.functions';
|
|
6
|
-
import { hasOwn, uniqueItems, commonItems } from './utility.functions';
|
|
7
|
-
import { JsonPointer, Pointer } from './jsonpointer.functions';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 'mergeSchemas' function
|
|
11
|
-
*
|
|
12
|
-
* Merges multiple JSON schemas into a single schema with combined rules.
|
|
13
|
-
*
|
|
14
|
-
* If able to logically merge properties from all schemas,
|
|
15
|
-
* returns a single schema object containing all merged properties.
|
|
16
|
-
*
|
|
17
|
-
* Example: ({ a: b, max: 1 }, { c: d, max: 2 }) => { a: b, c: d, max: 1 }
|
|
18
|
-
*
|
|
19
|
-
* If unable to logically merge, returns an allOf schema object containing
|
|
20
|
-
* an array of the original schemas;
|
|
21
|
-
*
|
|
22
|
-
* Example: ({ a: b }, { a: d }) => { allOf: [ { a: b }, { a: d } ] }
|
|
23
|
-
*
|
|
24
|
-
* // schemas - one or more input schemas
|
|
25
|
-
* // - merged schema
|
|
26
|
-
*/
|
|
27
|
-
export function mergeSchemas(...schemas) {
|
|
28
|
-
schemas = schemas.filter(schema => !isEmpty(schema));
|
|
29
|
-
if (schemas.some(schema => !isObject(schema))) { return null; }
|
|
30
|
-
const combinedSchema: any = {};
|
|
31
|
-
for (const schema of schemas) {
|
|
32
|
-
for (const key of Object.keys(schema)) {
|
|
33
|
-
const combinedValue = combinedSchema[key];
|
|
34
|
-
const schemaValue = schema[key];
|
|
35
|
-
if (!hasOwn(combinedSchema, key) || isEqual(combinedValue, schemaValue)) {
|
|
36
|
-
combinedSchema[key] = schemaValue;
|
|
37
|
-
} else {
|
|
38
|
-
switch (key) {
|
|
39
|
-
case 'allOf':
|
|
40
|
-
// Combine all items from both arrays
|
|
41
|
-
if (isArray(combinedValue) && isArray(schemaValue)) {
|
|
42
|
-
combinedSchema.allOf = mergeSchemas(...combinedValue, ...schemaValue);
|
|
43
|
-
} else {
|
|
44
|
-
return { allOf: [ ...schemas ] };
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
case 'additionalItems': case 'additionalProperties':
|
|
48
|
-
case 'contains': case 'propertyNames':
|
|
49
|
-
// Merge schema objects
|
|
50
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
51
|
-
combinedSchema[key] = mergeSchemas(combinedValue, schemaValue);
|
|
52
|
-
// additionalProperties == false in any schema overrides all other values
|
|
53
|
-
} else if (
|
|
54
|
-
key === 'additionalProperties' &&
|
|
55
|
-
(combinedValue === false || schemaValue === false)
|
|
56
|
-
) {
|
|
57
|
-
combinedSchema.combinedSchema = false;
|
|
58
|
-
} else {
|
|
59
|
-
return { allOf: [ ...schemas ] };
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case 'anyOf': case 'oneOf': case 'enum':
|
|
63
|
-
// Keep only items that appear in both arrays
|
|
64
|
-
if (isArray(combinedValue) && isArray(schemaValue)) {
|
|
65
|
-
combinedSchema[key] = combinedValue.filter(item1 =>
|
|
66
|
-
schemaValue.findIndex(item2 => isEqual(item1, item2)) > -1
|
|
67
|
-
);
|
|
68
|
-
if (!combinedSchema[key].length) { return { allOf: [ ...schemas ] }; }
|
|
69
|
-
} else {
|
|
70
|
-
return { allOf: [ ...schemas ] };
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
case 'definitions':
|
|
74
|
-
// Combine keys from both objects
|
|
75
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
76
|
-
const combinedObject = { ...combinedValue };
|
|
77
|
-
for (const subKey of Object.keys(schemaValue)) {
|
|
78
|
-
if (!hasOwn(combinedObject, subKey) ||
|
|
79
|
-
isEqual(combinedObject[subKey], schemaValue[subKey])
|
|
80
|
-
) {
|
|
81
|
-
combinedObject[subKey] = schemaValue[subKey];
|
|
82
|
-
// Don't combine matching keys with different values
|
|
83
|
-
} else {
|
|
84
|
-
return { allOf: [ ...schemas ] };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
combinedSchema.definitions = combinedObject;
|
|
88
|
-
} else {
|
|
89
|
-
return { allOf: [ ...schemas ] };
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
case 'dependencies':
|
|
93
|
-
// Combine all keys from both objects
|
|
94
|
-
// and merge schemas on matching keys,
|
|
95
|
-
// converting from arrays to objects if necessary
|
|
96
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
97
|
-
const combinedObject = { ...combinedValue };
|
|
98
|
-
for (const subKey of Object.keys(schemaValue)) {
|
|
99
|
-
if (!hasOwn(combinedObject, subKey) ||
|
|
100
|
-
isEqual(combinedObject[subKey], schemaValue[subKey])
|
|
101
|
-
) {
|
|
102
|
-
combinedObject[subKey] = schemaValue[subKey];
|
|
103
|
-
// If both keys are arrays, include all items from both arrays,
|
|
104
|
-
// excluding duplicates
|
|
105
|
-
} else if (
|
|
106
|
-
isArray(schemaValue[subKey]) && isArray(combinedObject[subKey])
|
|
107
|
-
) {
|
|
108
|
-
combinedObject[subKey] =
|
|
109
|
-
uniqueItems(...combinedObject[subKey], ...schemaValue[subKey]);
|
|
110
|
-
// If either key is an object, merge the schemas
|
|
111
|
-
} else if (
|
|
112
|
-
(isArray(schemaValue[subKey]) || isObject(schemaValue[subKey])) &&
|
|
113
|
-
(isArray(combinedObject[subKey]) || isObject(combinedObject[subKey]))
|
|
114
|
-
) {
|
|
115
|
-
// If either key is an array, convert it to an object first
|
|
116
|
-
const required = isArray(combinedSchema.required) ?
|
|
117
|
-
combinedSchema.required : [];
|
|
118
|
-
const combinedDependency = isArray(combinedObject[subKey]) ?
|
|
119
|
-
{ required: uniqueItems(...required, combinedObject[subKey]) } :
|
|
120
|
-
combinedObject[subKey];
|
|
121
|
-
const schemaDependency = isArray(schemaValue[subKey]) ?
|
|
122
|
-
{ required: uniqueItems(...required, schemaValue[subKey]) } :
|
|
123
|
-
schemaValue[subKey];
|
|
124
|
-
combinedObject[subKey] =
|
|
125
|
-
mergeSchemas(combinedDependency, schemaDependency);
|
|
126
|
-
} else {
|
|
127
|
-
return { allOf: [ ...schemas ] };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
combinedSchema.dependencies = combinedObject;
|
|
131
|
-
} else {
|
|
132
|
-
return { allOf: [ ...schemas ] };
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
case 'items':
|
|
136
|
-
// If arrays, keep only items that appear in both arrays
|
|
137
|
-
if (isArray(combinedValue) && isArray(schemaValue)) {
|
|
138
|
-
combinedSchema.items = combinedValue.filter(item1 =>
|
|
139
|
-
schemaValue.findIndex(item2 => isEqual(item1, item2)) > -1
|
|
140
|
-
);
|
|
141
|
-
if (!combinedSchema.items.length) { return { allOf: [ ...schemas ] }; }
|
|
142
|
-
// If both keys are objects, merge them
|
|
143
|
-
} else if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
144
|
-
combinedSchema.items = mergeSchemas(combinedValue, schemaValue);
|
|
145
|
-
// If object + array, combine object with each array item
|
|
146
|
-
} else if (isArray(combinedValue) && isObject(schemaValue)) {
|
|
147
|
-
combinedSchema.items =
|
|
148
|
-
combinedValue.map(item => mergeSchemas(item, schemaValue));
|
|
149
|
-
} else if (isObject(combinedValue) && isArray(schemaValue)) {
|
|
150
|
-
combinedSchema.items =
|
|
151
|
-
schemaValue.map(item => mergeSchemas(item, combinedValue));
|
|
152
|
-
} else {
|
|
153
|
-
return { allOf: [ ...schemas ] };
|
|
154
|
-
}
|
|
155
|
-
break;
|
|
156
|
-
case 'multipleOf':
|
|
157
|
-
// TODO: Adjust to correctly handle decimal values
|
|
158
|
-
// If numbers, set to least common multiple
|
|
159
|
-
if (isNumber(combinedValue) && isNumber(schemaValue)) {
|
|
160
|
-
const gcd = (x, y) => !y ? x : gcd(y, x % y);
|
|
161
|
-
const lcm = (x, y) => (x * y) / gcd(x, y);
|
|
162
|
-
combinedSchema.multipleOf = lcm(combinedValue, schemaValue);
|
|
163
|
-
} else {
|
|
164
|
-
return { allOf: [ ...schemas ] };
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
case 'maximum': case 'exclusiveMaximum': case 'maxLength':
|
|
168
|
-
case 'maxItems': case 'maxProperties':
|
|
169
|
-
// If numbers, set to lowest value
|
|
170
|
-
if (isNumber(combinedValue) && isNumber(schemaValue)) {
|
|
171
|
-
combinedSchema[key] = Math.min(combinedValue, schemaValue);
|
|
172
|
-
} else {
|
|
173
|
-
return { allOf: [ ...schemas ] };
|
|
174
|
-
}
|
|
175
|
-
break;
|
|
176
|
-
case 'minimum': case 'exclusiveMinimum': case 'minLength':
|
|
177
|
-
case 'minItems': case 'minProperties':
|
|
178
|
-
// If numbers, set to highest value
|
|
179
|
-
if (isNumber(combinedValue) && isNumber(schemaValue)) {
|
|
180
|
-
combinedSchema[key] = Math.max(combinedValue, schemaValue);
|
|
181
|
-
} else {
|
|
182
|
-
return { allOf: [ ...schemas ] };
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
case 'not':
|
|
186
|
-
// Combine not values into anyOf array
|
|
187
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
188
|
-
const notAnyOf = [combinedValue, schemaValue]
|
|
189
|
-
.reduce((notAnyOfArray, notSchema) =>
|
|
190
|
-
isArray(notSchema.anyOf) &&
|
|
191
|
-
Object.keys(notSchema).length === 1 ?
|
|
192
|
-
[ ...notAnyOfArray, ...notSchema.anyOf ] :
|
|
193
|
-
[ ...notAnyOfArray, notSchema ]
|
|
194
|
-
, []);
|
|
195
|
-
// TODO: Remove duplicate items from array
|
|
196
|
-
combinedSchema.not = { anyOf: notAnyOf };
|
|
197
|
-
} else {
|
|
198
|
-
return { allOf: [ ...schemas ] };
|
|
199
|
-
}
|
|
200
|
-
break;
|
|
201
|
-
case 'patternProperties':
|
|
202
|
-
// Combine all keys from both objects
|
|
203
|
-
// and merge schemas on matching keys
|
|
204
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
205
|
-
const combinedObject = { ...combinedValue };
|
|
206
|
-
for (const subKey of Object.keys(schemaValue)) {
|
|
207
|
-
if (!hasOwn(combinedObject, subKey) ||
|
|
208
|
-
isEqual(combinedObject[subKey], schemaValue[subKey])
|
|
209
|
-
) {
|
|
210
|
-
combinedObject[subKey] = schemaValue[subKey];
|
|
211
|
-
// If both keys are objects, merge them
|
|
212
|
-
} else if (
|
|
213
|
-
isObject(schemaValue[subKey]) && isObject(combinedObject[subKey])
|
|
214
|
-
) {
|
|
215
|
-
combinedObject[subKey] =
|
|
216
|
-
mergeSchemas(combinedObject[subKey], schemaValue[subKey]);
|
|
217
|
-
} else {
|
|
218
|
-
return { allOf: [ ...schemas ] };
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
combinedSchema.patternProperties = combinedObject;
|
|
222
|
-
} else {
|
|
223
|
-
return { allOf: [ ...schemas ] };
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
case 'properties':
|
|
227
|
-
// Combine all keys from both objects
|
|
228
|
-
// unless additionalProperties === false
|
|
229
|
-
// and merge schemas on matching keys
|
|
230
|
-
if (isObject(combinedValue) && isObject(schemaValue)) {
|
|
231
|
-
const combinedObject = { ...combinedValue };
|
|
232
|
-
// If new schema has additionalProperties,
|
|
233
|
-
// merge or remove non-matching property keys in combined schema
|
|
234
|
-
if (hasOwn(schemaValue, 'additionalProperties')) {
|
|
235
|
-
Object.keys(combinedValue)
|
|
236
|
-
.filter(combinedKey => !Object.keys(schemaValue).includes(combinedKey))
|
|
237
|
-
.forEach(nonMatchingKey => {
|
|
238
|
-
if (schemaValue.additionalProperties === false) {
|
|
239
|
-
delete combinedObject[nonMatchingKey];
|
|
240
|
-
} else if (isObject(schemaValue.additionalProperties)) {
|
|
241
|
-
combinedObject[nonMatchingKey] = mergeSchemas(
|
|
242
|
-
combinedObject[nonMatchingKey],
|
|
243
|
-
schemaValue.additionalProperties
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
for (const subKey of Object.keys(schemaValue)) {
|
|
249
|
-
if (isEqual(combinedObject[subKey], schemaValue[subKey]) || (
|
|
250
|
-
!hasOwn(combinedObject, subKey) &&
|
|
251
|
-
!hasOwn(combinedObject, 'additionalProperties')
|
|
252
|
-
)) {
|
|
253
|
-
combinedObject[subKey] = schemaValue[subKey];
|
|
254
|
-
// If combined schema has additionalProperties,
|
|
255
|
-
// merge or ignore non-matching property keys in new schema
|
|
256
|
-
} else if (
|
|
257
|
-
!hasOwn(combinedObject, subKey) &&
|
|
258
|
-
hasOwn(combinedObject, 'additionalProperties')
|
|
259
|
-
) {
|
|
260
|
-
// If combinedObject.additionalProperties === false,
|
|
261
|
-
// do nothing (don't set key)
|
|
262
|
-
// If additionalProperties is object, merge with new key
|
|
263
|
-
if (isObject(combinedObject.additionalProperties)) {
|
|
264
|
-
combinedObject[subKey] = mergeSchemas(
|
|
265
|
-
combinedObject.additionalProperties, schemaValue[subKey]
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
// If both keys are objects, merge them
|
|
269
|
-
} else if (
|
|
270
|
-
isObject(schemaValue[subKey]) &&
|
|
271
|
-
isObject(combinedObject[subKey])
|
|
272
|
-
) {
|
|
273
|
-
combinedObject[subKey] =
|
|
274
|
-
mergeSchemas(combinedObject[subKey], schemaValue[subKey]);
|
|
275
|
-
} else {
|
|
276
|
-
return { allOf: [ ...schemas ] };
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
combinedSchema.properties = combinedObject;
|
|
280
|
-
} else {
|
|
281
|
-
return { allOf: [ ...schemas ] };
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
case 'required':
|
|
285
|
-
// If arrays, include all items from both arrays, excluding duplicates
|
|
286
|
-
if (isArray(combinedValue) && isArray(schemaValue)) {
|
|
287
|
-
combinedSchema.required = uniqueItems(...combinedValue, ...schemaValue);
|
|
288
|
-
// If booleans, aet true if either true
|
|
289
|
-
} else if (
|
|
290
|
-
typeof schemaValue === 'boolean' &&
|
|
291
|
-
typeof combinedValue === 'boolean'
|
|
292
|
-
) {
|
|
293
|
-
combinedSchema.required = !!combinedValue || !!schemaValue;
|
|
294
|
-
} else {
|
|
295
|
-
return { allOf: [ ...schemas ] };
|
|
296
|
-
}
|
|
297
|
-
break;
|
|
298
|
-
case '$schema': case '$id': case 'id':
|
|
299
|
-
// Don't combine these keys
|
|
300
|
-
break;
|
|
301
|
-
case 'title': case 'description': case '$comment':
|
|
302
|
-
// Return the last value, overwriting any previous one
|
|
303
|
-
// These properties are not used for validation, so conflicts don't matter
|
|
304
|
-
combinedSchema[key] = schemaValue;
|
|
305
|
-
break;
|
|
306
|
-
case 'type':
|
|
307
|
-
if (
|
|
308
|
-
(isArray(schemaValue) || isString(schemaValue)) &&
|
|
309
|
-
(isArray(combinedValue) || isString(combinedValue))
|
|
310
|
-
) {
|
|
311
|
-
const combinedTypes = commonItems(combinedValue, schemaValue);
|
|
312
|
-
if (!combinedTypes.length) { return { allOf: [ ...schemas ] }; }
|
|
313
|
-
combinedSchema.type = combinedTypes.length > 1 ? combinedTypes : combinedTypes[0];
|
|
314
|
-
} else {
|
|
315
|
-
return { allOf: [ ...schemas ] };
|
|
316
|
-
}
|
|
317
|
-
break;
|
|
318
|
-
case 'uniqueItems':
|
|
319
|
-
// Set true if either true
|
|
320
|
-
combinedSchema.uniqueItems = !!combinedValue || !!schemaValue;
|
|
321
|
-
break;
|
|
322
|
-
default:
|
|
323
|
-
return { allOf: [ ...schemas ] };
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return combinedSchema;
|
|
329
|
-
}
|