@ng-formworks/core 17.2.7 → 17.3.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.
Files changed (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +833 -0
  3. package/esm2022/lib/framework-library/framework-library.service.mjs +175 -0
  4. package/esm2022/lib/framework-library/framework.mjs +15 -0
  5. package/esm2022/lib/framework-library/no-framework.component.mjs +18 -0
  6. package/esm2022/lib/framework-library/no-framework.module.mjs +27 -0
  7. package/esm2022/lib/framework-library/no.framework.mjs +19 -0
  8. package/esm2022/lib/json-schema-form.component.mjs +765 -0
  9. package/esm2022/lib/json-schema-form.module.mjs +26 -0
  10. package/esm2022/lib/json-schema-form.service.mjs +676 -0
  11. package/esm2022/lib/locale/de-validation-messages.mjs +60 -0
  12. package/esm2022/lib/locale/en-validation-messages.mjs +60 -0
  13. package/esm2022/lib/locale/es-validation-messages.mjs +57 -0
  14. package/esm2022/lib/locale/fr-validation-messages.mjs +60 -0
  15. package/esm2022/lib/locale/index.mjs +8 -0
  16. package/esm2022/lib/locale/it-validation-messages.mjs +60 -0
  17. package/esm2022/lib/locale/pt-validation-messages.mjs +60 -0
  18. package/esm2022/lib/locale/zh-validation-messages.mjs +60 -0
  19. package/esm2022/lib/shared/convert-schema-to-draft6.function.mjs +300 -0
  20. package/esm2022/lib/shared/form-group.functions.mjs +442 -0
  21. package/esm2022/lib/shared/format-regex.constants.mjs +54 -0
  22. package/esm2022/lib/shared/index.mjs +12 -0
  23. package/esm2022/lib/shared/json-schema.functions.mjs +784 -0
  24. package/esm2022/lib/shared/json.validators.mjs +884 -0
  25. package/esm2022/lib/shared/jsonpointer.functions.mjs +1026 -0
  26. package/esm2022/lib/shared/layout.functions.mjs +1154 -0
  27. package/esm2022/lib/shared/merge-schemas.function.mjs +345 -0
  28. package/esm2022/lib/shared/utility.functions.mjs +380 -0
  29. package/esm2022/lib/shared/validator.functions.mjs +584 -0
  30. package/esm2022/lib/widget-library/add-reference.component.mjs +61 -0
  31. package/esm2022/lib/widget-library/button.component.mjs +72 -0
  32. package/esm2022/lib/widget-library/checkbox.component.mjs +105 -0
  33. package/esm2022/lib/widget-library/checkboxes.component.mjs +147 -0
  34. package/esm2022/lib/widget-library/file.component.mjs +35 -0
  35. package/esm2022/lib/widget-library/hidden.component.mjs +54 -0
  36. package/esm2022/lib/widget-library/index.mjs +55 -0
  37. package/esm2022/lib/widget-library/input.component.mjs +119 -0
  38. package/esm2022/lib/widget-library/message.component.mjs +38 -0
  39. package/esm2022/lib/widget-library/none.component.mjs +21 -0
  40. package/esm2022/lib/widget-library/number.component.mjs +123 -0
  41. package/esm2022/lib/widget-library/one-of.component.mjs +35 -0
  42. package/esm2022/lib/widget-library/orderable.directive.mjs +123 -0
  43. package/esm2022/lib/widget-library/radios.component.mjs +153 -0
  44. package/esm2022/lib/widget-library/root.component.mjs +79 -0
  45. package/esm2022/lib/widget-library/section.component.mjs +199 -0
  46. package/esm2022/lib/widget-library/select-framework.component.mjs +51 -0
  47. package/esm2022/lib/widget-library/select-widget.component.mjs +46 -0
  48. package/esm2022/lib/widget-library/select.component.mjs +150 -0
  49. package/esm2022/lib/widget-library/submit.component.mjs +82 -0
  50. package/esm2022/lib/widget-library/tab.component.mjs +41 -0
  51. package/esm2022/lib/widget-library/tabs.component.mjs +108 -0
  52. package/esm2022/lib/widget-library/template.component.mjs +46 -0
  53. package/esm2022/lib/widget-library/textarea.component.mjs +104 -0
  54. package/esm2022/lib/widget-library/widget-library.module.mjs +42 -0
  55. package/esm2022/lib/widget-library/widget-library.service.mjs +226 -0
  56. package/esm2022/ng-formworks-core.mjs +5 -0
  57. package/esm2022/public_api.mjs +13 -0
  58. package/fesm2022/ng-formworks-core.mjs +10147 -0
  59. package/fesm2022/ng-formworks-core.mjs.map +1 -0
  60. package/index.d.ts +5 -0
  61. package/lib/framework-library/framework-library.service.d.ts +55 -0
  62. package/lib/framework-library/framework.d.ts +13 -0
  63. package/lib/framework-library/no-framework.component.d.ts +8 -0
  64. package/lib/framework-library/no-framework.module.d.ts +9 -0
  65. package/lib/framework-library/no.framework.d.ts +10 -0
  66. package/lib/json-schema-form.component.d.ts +218 -0
  67. package/lib/json-schema-form.module.d.ts +11 -0
  68. package/lib/json-schema-form.service.d.ts +115 -0
  69. package/lib/locale/de-validation-messages.d.ts +1 -0
  70. package/lib/locale/en-validation-messages.d.ts +1 -0
  71. package/lib/locale/es-validation-messages.d.ts +1 -0
  72. package/lib/locale/fr-validation-messages.d.ts +1 -0
  73. package/{src/lib/locale/index.ts → lib/locale/index.d.ts} +7 -7
  74. package/lib/locale/it-validation-messages.d.ts +1 -0
  75. package/lib/locale/pt-validation-messages.d.ts +1 -0
  76. package/lib/locale/zh-validation-messages.d.ts +1 -0
  77. package/lib/shared/convert-schema-to-draft6.function.d.ts +21 -0
  78. package/lib/shared/form-group.functions.d.ts +100 -0
  79. package/lib/shared/format-regex.constants.d.ts +19 -0
  80. package/lib/shared/index.d.ts +9 -0
  81. package/lib/shared/json-schema.functions.d.ts +193 -0
  82. package/lib/shared/json.validators.d.ts +441 -0
  83. package/lib/shared/jsonpointer.functions.d.ts +416 -0
  84. package/lib/shared/layout.functions.d.ts +83 -0
  85. package/lib/shared/merge-schemas.function.d.ts +19 -0
  86. package/lib/shared/utility.functions.d.ts +165 -0
  87. package/{src/lib/shared/validator.functions.ts → lib/shared/validator.functions.d.ts} +364 -601
  88. package/lib/widget-library/add-reference.component.d.ts +20 -0
  89. package/lib/widget-library/button.component.d.ts +21 -0
  90. package/lib/widget-library/checkbox.component.d.ts +24 -0
  91. package/lib/widget-library/checkboxes.component.d.ts +24 -0
  92. package/lib/widget-library/file.component.d.ts +21 -0
  93. package/lib/widget-library/hidden.component.d.ts +19 -0
  94. package/{src/lib/widget-library/index.ts → lib/widget-library/index.d.ts} +47 -56
  95. package/lib/widget-library/input.component.d.ts +22 -0
  96. package/lib/widget-library/message.component.d.ts +15 -0
  97. package/lib/widget-library/none.component.d.ts +8 -0
  98. package/lib/widget-library/number.component.d.ts +25 -0
  99. package/lib/widget-library/one-of.component.d.ts +21 -0
  100. package/lib/widget-library/orderable.directive.d.ts +41 -0
  101. package/lib/widget-library/radios.component.d.ts +23 -0
  102. package/lib/widget-library/root.component.d.ts +17 -0
  103. package/lib/widget-library/section.component.d.ts +19 -0
  104. package/lib/widget-library/select-framework.component.d.ts +18 -0
  105. package/lib/widget-library/select-widget.component.d.ts +18 -0
  106. package/lib/widget-library/select.component.d.ts +24 -0
  107. package/lib/widget-library/submit.component.d.ts +24 -0
  108. package/lib/widget-library/tab.component.d.ts +14 -0
  109. package/lib/widget-library/tabs.component.d.ts +20 -0
  110. package/lib/widget-library/template.component.d.ts +18 -0
  111. package/lib/widget-library/textarea.component.d.ts +21 -0
  112. package/lib/widget-library/widget-library.module.d.ts +31 -0
  113. package/lib/widget-library/widget-library.service.d.ts +22 -0
  114. package/package.json +64 -53
  115. package/{src/public_api.ts → public_api.d.ts} +9 -21
  116. package/karma.conf.js +0 -46
  117. package/ng-package.json +0 -11
  118. package/src/lib/framework-library/framework-library.service.ts +0 -195
  119. package/src/lib/framework-library/framework.ts +0 -11
  120. package/src/lib/framework-library/no-framework.component.html +0 -2
  121. package/src/lib/framework-library/no-framework.component.ts +0 -11
  122. package/src/lib/framework-library/no-framework.module.ts +0 -18
  123. package/src/lib/framework-library/no.framework.ts +0 -11
  124. package/src/lib/json-schema-form.component.html +0 -7
  125. package/src/lib/json-schema-form.component.ts +0 -809
  126. package/src/lib/json-schema-form.module.ts +0 -17
  127. package/src/lib/json-schema-form.service.ts +0 -907
  128. package/src/lib/locale/de-validation-messages.ts +0 -58
  129. package/src/lib/locale/en-validation-messages.ts +0 -58
  130. package/src/lib/locale/es-validation-messages.ts +0 -55
  131. package/src/lib/locale/fr-validation-messages.ts +0 -58
  132. package/src/lib/locale/it-validation-messages.ts +0 -58
  133. package/src/lib/locale/pt-validation-messages.ts +0 -58
  134. package/src/lib/locale/zh-validation-messages.ts +0 -58
  135. package/src/lib/locale-dates/en-US.ts +0 -5
  136. package/src/lib/shared/convert-schema-to-draft6.function.ts +0 -321
  137. package/src/lib/shared/form-group.functions.ts +0 -522
  138. package/src/lib/shared/format-regex.constants.ts +0 -73
  139. package/src/lib/shared/index.ts +0 -40
  140. package/src/lib/shared/json-schema.functions.ts +0 -788
  141. package/src/lib/shared/json.validators.ts +0 -878
  142. package/src/lib/shared/jsonpointer.functions.ts +0 -1012
  143. package/src/lib/shared/jspointer.functions.json.spec.ts +0 -103
  144. package/src/lib/shared/layout.functions.ts +0 -1233
  145. package/src/lib/shared/merge-schemas.function.ts +0 -329
  146. package/src/lib/shared/utility.functions.ts +0 -373
  147. package/src/lib/shared/validator.functions.spec.ts +0 -55
  148. package/src/lib/widget-library/add-reference.component.ts +0 -59
  149. package/src/lib/widget-library/button.component.ts +0 -54
  150. package/src/lib/widget-library/checkbox.component.ts +0 -74
  151. package/src/lib/widget-library/checkboxes.component.ts +0 -104
  152. package/src/lib/widget-library/file.component.ts +0 -36
  153. package/src/lib/widget-library/hidden.component.ts +0 -39
  154. package/src/lib/widget-library/input.component.ts +0 -76
  155. package/src/lib/widget-library/message.component.ts +0 -29
  156. package/src/lib/widget-library/none.component.ts +0 -12
  157. package/src/lib/widget-library/number.component.ts +0 -79
  158. package/src/lib/widget-library/one-of.component.ts +0 -36
  159. package/src/lib/widget-library/orderable.directive.ts +0 -130
  160. package/src/lib/widget-library/radios.component.ts +0 -101
  161. package/src/lib/widget-library/root.component.ts +0 -78
  162. package/src/lib/widget-library/section.component.ts +0 -133
  163. package/src/lib/widget-library/select-framework.component.ts +0 -50
  164. package/src/lib/widget-library/select-widget.component.ts +0 -46
  165. package/src/lib/widget-library/select.component.ts +0 -96
  166. package/src/lib/widget-library/submit.component.ts +0 -68
  167. package/src/lib/widget-library/tab.component.ts +0 -29
  168. package/src/lib/widget-library/tabs.component.ts +0 -83
  169. package/src/lib/widget-library/template.component.ts +0 -52
  170. package/src/lib/widget-library/textarea.component.ts +0 -68
  171. package/src/lib/widget-library/widget-library.module.ts +0 -13
  172. package/src/lib/widget-library/widget-library.service.ts +0 -234
  173. package/src/test.ts +0 -18
  174. package/tsconfig.lib.json +0 -25
  175. package/tsconfig.lib.prod.json +0 -9
  176. package/tsconfig.spec.json +0 -17
  177. package/tslint.json +0 -11
@@ -1,321 +0,0 @@
1
- import cloneDeep from 'lodash/cloneDeep';
2
-
3
- /**
4
- * 'convertSchemaToDraft6' function
5
- *
6
- * Converts a JSON Schema from draft 1 through 4 format to draft 6 format
7
- *
8
- * Inspired by on geraintluff's JSON Schema 3 to 4 compatibility function:
9
- * https://github.com/geraintluff/json-schema-compatibility
10
- * Also uses suggestions from AJV's JSON Schema 4 to 6 migration guide:
11
- * https://github.com/epoberezkin/ajv/releases/tag/5.0.0
12
- * And additional details from the official JSON Schema documentation:
13
- * http://json-schema.org
14
- *
15
- * // { object } originalSchema - JSON schema (draft 1, 2, 3, 4, or 6)
16
- * // { OptionObject = {} } options - options: parent schema changed?, schema draft number?
17
- * // { object } - JSON schema (draft 6)
18
- */
19
- export interface OptionObject { changed?: boolean; draft?: number; }
20
- export function convertSchemaToDraft6(schema, options: OptionObject = {}) {
21
- let draft: number = options.draft || null;
22
- let changed: boolean = options.changed || false;
23
-
24
- if (typeof schema !== 'object') { return schema; }
25
- if (typeof schema.map === 'function') {
26
- return [...schema.map(subSchema => convertSchemaToDraft6(subSchema, { changed, draft }))];
27
- }
28
- let newSchema = { ...schema };
29
- const simpleTypes = ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'];
30
-
31
- if (typeof newSchema.$schema === 'string' &&
32
- /http\:\/\/json\-schema\.org\/draft\-0\d\/schema\#/.test(newSchema.$schema)
33
- ) {
34
- draft = newSchema.$schema[30];
35
- }
36
-
37
- // Convert v1-v2 'contentEncoding' to 'media.binaryEncoding'
38
- // Note: This is only used in JSON hyper-schema (not regular JSON schema)
39
- if (newSchema.contentEncoding) {
40
- newSchema.media = { binaryEncoding: newSchema.contentEncoding };
41
- delete newSchema.contentEncoding;
42
- changed = true;
43
- }
44
-
45
- // Convert v1-v3 'extends' to 'allOf'
46
- if (typeof newSchema.extends === 'object') {
47
- newSchema.allOf = typeof newSchema.extends.map === 'function' ?
48
- newSchema.extends.map(subSchema => convertSchemaToDraft6(subSchema, { changed, draft })) :
49
- [convertSchemaToDraft6(newSchema.extends, { changed, draft })];
50
- delete newSchema.extends;
51
- changed = true;
52
- }
53
-
54
- // Convert v1-v3 'disallow' to 'not'
55
- if (newSchema.disallow) {
56
- if (typeof newSchema.disallow === 'string') {
57
- newSchema.not = { type: newSchema.disallow };
58
- } else if (typeof newSchema.disallow.map === 'function') {
59
- newSchema.not = {
60
- anyOf: newSchema.disallow
61
- .map(type => typeof type === 'object' ? type : { type })
62
- };
63
- }
64
- delete newSchema.disallow;
65
- changed = true;
66
- }
67
-
68
- // Convert v3 string 'dependencies' properties to arrays
69
- if (typeof newSchema.dependencies === 'object' &&
70
- Object.keys(newSchema.dependencies)
71
- .some(key => typeof newSchema.dependencies[key] === 'string')
72
- ) {
73
- newSchema.dependencies = { ...newSchema.dependencies };
74
- Object.keys(newSchema.dependencies)
75
- .filter(key => typeof newSchema.dependencies[key] === 'string')
76
- .forEach(key => newSchema.dependencies[key] = [newSchema.dependencies[key]]);
77
- changed = true;
78
- }
79
-
80
- // Convert v1 'maxDecimal' to 'multipleOf'
81
- if (typeof newSchema.maxDecimal === 'number') {
82
- newSchema.multipleOf = 1 / Math.pow(10, newSchema.maxDecimal);
83
- delete newSchema.divisibleBy;
84
- changed = true;
85
- if (!draft || draft === 2) { draft = 1; }
86
- }
87
-
88
- // Convert v2-v3 'divisibleBy' to 'multipleOf'
89
- if (typeof newSchema.divisibleBy === 'number') {
90
- newSchema.multipleOf = newSchema.divisibleBy;
91
- delete newSchema.divisibleBy;
92
- changed = true;
93
- }
94
-
95
- // Convert v1-v2 boolean 'minimumCanEqual' to 'exclusiveMinimum'
96
- if (typeof newSchema.minimum === 'number' && newSchema.minimumCanEqual === false) {
97
- newSchema.exclusiveMinimum = newSchema.minimum;
98
- delete newSchema.minimum;
99
- changed = true;
100
- if (!draft) { draft = 2; }
101
- } else if (typeof newSchema.minimumCanEqual === 'boolean') {
102
- delete newSchema.minimumCanEqual;
103
- changed = true;
104
- if (!draft) { draft = 2; }
105
- }
106
-
107
- // Convert v3-v4 boolean 'exclusiveMinimum' to numeric
108
- if (typeof newSchema.minimum === 'number' && newSchema.exclusiveMinimum === true) {
109
- newSchema.exclusiveMinimum = newSchema.minimum;
110
- delete newSchema.minimum;
111
- changed = true;
112
- } else if (typeof newSchema.exclusiveMinimum === 'boolean') {
113
- delete newSchema.exclusiveMinimum;
114
- changed = true;
115
- }
116
-
117
- // Convert v1-v2 boolean 'maximumCanEqual' to 'exclusiveMaximum'
118
- if (typeof newSchema.maximum === 'number' && newSchema.maximumCanEqual === false) {
119
- newSchema.exclusiveMaximum = newSchema.maximum;
120
- delete newSchema.maximum;
121
- changed = true;
122
- if (!draft) { draft = 2; }
123
- } else if (typeof newSchema.maximumCanEqual === 'boolean') {
124
- delete newSchema.maximumCanEqual;
125
- changed = true;
126
- if (!draft) { draft = 2; }
127
- }
128
-
129
- // Convert v3-v4 boolean 'exclusiveMaximum' to numeric
130
- if (typeof newSchema.maximum === 'number' && newSchema.exclusiveMaximum === true) {
131
- newSchema.exclusiveMaximum = newSchema.maximum;
132
- delete newSchema.maximum;
133
- changed = true;
134
- } else if (typeof newSchema.exclusiveMaximum === 'boolean') {
135
- delete newSchema.exclusiveMaximum;
136
- changed = true;
137
- }
138
-
139
- // Search object 'properties' for 'optional', 'required', and 'requires' items,
140
- // and convert them into object 'required' arrays and 'dependencies' objects
141
- if (typeof newSchema.properties === 'object') {
142
- const properties = { ...newSchema.properties };
143
- const requiredKeys = Array.isArray(newSchema.required) ?
144
- new Set(newSchema.required) : new Set();
145
-
146
- // Convert v1-v2 boolean 'optional' properties to 'required' array
147
- if (draft === 1 || draft === 2 ||
148
- Object.keys(properties).some(key => properties[key].optional === true)
149
- ) {
150
- Object.keys(properties)
151
- .filter(key => properties[key].optional !== true)
152
- .forEach(key => requiredKeys.add(key));
153
- changed = true;
154
- if (!draft) { draft = 2; }
155
- }
156
-
157
- // Convert v3 boolean 'required' properties to 'required' array
158
- if (Object.keys(properties).some(key => properties[key].required === true)) {
159
- Object.keys(properties)
160
- .filter(key => properties[key].required === true)
161
- .forEach(key => requiredKeys.add(key));
162
- changed = true;
163
- }
164
-
165
- if (requiredKeys.size) { newSchema.required = Array.from(requiredKeys); }
166
-
167
- // Convert v1-v2 array or string 'requires' properties to 'dependencies' object
168
- if (Object.keys(properties).some(key => properties[key].requires)) {
169
- const dependencies = typeof newSchema.dependencies === 'object' ?
170
- { ...newSchema.dependencies } : {};
171
- Object.keys(properties)
172
- .filter(key => properties[key].requires)
173
- .forEach(key => dependencies[key] =
174
- typeof properties[key].requires === 'string' ?
175
- [properties[key].requires] : properties[key].requires
176
- );
177
- newSchema.dependencies = dependencies;
178
- changed = true;
179
- if (!draft) { draft = 2; }
180
- }
181
-
182
- newSchema.properties = properties;
183
- }
184
-
185
- // Revove v1-v2 boolean 'optional' key
186
- if (typeof newSchema.optional === 'boolean') {
187
- delete newSchema.optional;
188
- changed = true;
189
- if (!draft) { draft = 2; }
190
- }
191
-
192
- // Revove v1-v2 'requires' key
193
- if (newSchema.requires) {
194
- delete newSchema.requires;
195
- }
196
-
197
- // Revove v3 boolean 'required' key
198
- if (typeof newSchema.required === 'boolean') {
199
- delete newSchema.required;
200
- }
201
-
202
- // Convert id to $id
203
- if (typeof newSchema.id === 'string' && !newSchema.$id) {
204
- if (newSchema.id.slice(-1) === '#') {
205
- newSchema.id = newSchema.id.slice(0, -1);
206
- }
207
- newSchema.$id = newSchema.id + '-CONVERTED-TO-DRAFT-06#';
208
- delete newSchema.id;
209
- changed = true;
210
- }
211
-
212
- // Check if v1-v3 'any' or object types will be converted
213
- if (newSchema.type && (typeof newSchema.type.every === 'function' ?
214
- !newSchema.type.every(type => simpleTypes.includes(type)) :
215
- !simpleTypes.includes(newSchema.type)
216
- )) {
217
- changed = true;
218
- }
219
-
220
- // If schema changed, update or remove $schema identifier
221
- if (typeof newSchema.$schema === 'string' &&
222
- /http\:\/\/json\-schema\.org\/draft\-0[1-4]\/schema\#/.test(newSchema.$schema)
223
- ) {
224
- newSchema.$schema = 'http://json-schema.org/draft-06/schema#';
225
- changed = true;
226
- } else if (changed && typeof newSchema.$schema === 'string') {
227
- const addToDescription = 'Converted to draft 6 from ' + newSchema.$schema;
228
- if (typeof newSchema.description === 'string' && newSchema.description.length) {
229
- newSchema.description += '\n' + addToDescription;
230
- } else {
231
- newSchema.description = addToDescription;
232
- }
233
- delete newSchema.$schema;
234
- }
235
-
236
- // Convert v1-v3 'any' and object types
237
- if (newSchema.type && (typeof newSchema.type.every === 'function' ?
238
- !newSchema.type.every(type => simpleTypes.includes(type)) :
239
- !simpleTypes.includes(newSchema.type)
240
- )) {
241
- if (newSchema.type.length === 1) { newSchema.type = newSchema.type[0]; }
242
- if (typeof newSchema.type === 'string') {
243
- // Convert string 'any' type to array of all standard types
244
- if (newSchema.type === 'any') {
245
- newSchema.type = simpleTypes;
246
- // Delete non-standard string type
247
- } else {
248
- delete newSchema.type;
249
- }
250
- } else if (typeof newSchema.type === 'object') {
251
- if (typeof newSchema.type.every === 'function') {
252
- // If array of strings, only allow standard types
253
- if (newSchema.type.every(type => typeof type === 'string')) {
254
- newSchema.type = newSchema.type.some(type => type === 'any') ?
255
- newSchema.type = simpleTypes :
256
- newSchema.type.filter(type => simpleTypes.includes(type));
257
- // If type is an array with objects, convert the current schema to an 'anyOf' array
258
- } else if (newSchema.type.length > 1) {
259
- const arrayKeys = ['additionalItems', 'items', 'maxItems', 'minItems', 'uniqueItems', 'contains'];
260
- const numberKeys = ['multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum'];
261
- const objectKeys = ['maxProperties', 'minProperties', 'required', 'additionalProperties',
262
- 'properties', 'patternProperties', 'dependencies', 'propertyNames'];
263
- const stringKeys = ['maxLength', 'minLength', 'pattern', 'format'];
264
- const filterKeys = {
265
- 'array': [...numberKeys, ...objectKeys, ...stringKeys],
266
- 'integer': [...arrayKeys, ...objectKeys, ...stringKeys],
267
- 'number': [...arrayKeys, ...objectKeys, ...stringKeys],
268
- 'object': [...arrayKeys, ...numberKeys, ...stringKeys],
269
- 'string': [...arrayKeys, ...numberKeys, ...objectKeys],
270
- 'all': [...arrayKeys, ...numberKeys, ...objectKeys, ...stringKeys],
271
- };
272
- const anyOf = [];
273
- for (const type of newSchema.type) {
274
- const newType = typeof type === 'string' ? { type } : { ...type };
275
- Object.keys(newSchema)
276
- .filter(key => !newType.hasOwnProperty(key) &&
277
- ![...(filterKeys[newType.type] || filterKeys.all), 'type', 'default']
278
- .includes(key)
279
- )
280
- .forEach(key => newType[key] = newSchema[key]);
281
- anyOf.push(newType);
282
- }
283
- newSchema = newSchema.hasOwnProperty('default') ?
284
- { anyOf, default: newSchema.default } : { anyOf };
285
- // If type is an object, merge it with the current schema
286
- } else {
287
- const typeSchema = newSchema.type;
288
- delete newSchema.type;
289
- Object.assign(newSchema, typeSchema);
290
- }
291
- }
292
- } else {
293
- delete newSchema.type;
294
- }
295
- }
296
-
297
- // Convert sub schemas
298
- Object.keys(newSchema)
299
- .filter(key => typeof newSchema[key] === 'object')
300
- .forEach(key => {
301
- if (
302
- ['definitions', 'dependencies', 'properties', 'patternProperties']
303
- .includes(key) && typeof newSchema[key].map !== 'function'
304
- ) {
305
- const newKey = {};
306
- Object.keys(newSchema[key]).forEach(subKey => newKey[subKey] =
307
- convertSchemaToDraft6(newSchema[key][subKey], { changed, draft })
308
- );
309
- newSchema[key] = newKey;
310
- } else if (
311
- ['items', 'additionalItems', 'additionalProperties',
312
- 'allOf', 'anyOf', 'oneOf', 'not'].includes(key)
313
- ) {
314
- newSchema[key] = convertSchemaToDraft6(newSchema[key], { changed, draft });
315
- } else {
316
- newSchema[key] = cloneDeep(newSchema[key]);
317
- }
318
- });
319
-
320
- return newSchema;
321
- }