@@ -138,8 +138,18 @@ export function transformSchemaObjectWithComposition(
138
138
* Object + composition (anyOf/allOf/oneOf) types
139
139
*/
140
140
141
- /** Collect oneOf/allOf/anyOf with Omit<> for discriminators */
142
- function collectCompositions (
141
+ /** Collect oneOf/anyOf */
142
+ function collectUnionCompositions ( items : ( SchemaObject | ReferenceObject ) [ ] ) {
143
+ const output : ts . TypeNode [ ] = [ ] ;
144
+ for ( const item of items ) {
145
+ output . push ( transformSchemaObject ( item , options ) ) ;
146
+ }
147
+
148
+ return output ;
149
+ }
150
+
151
+ /** Collect allOf with Omit<> for discriminators */
152
+ function collectAllOfCompositions (
143
153
items : ( SchemaObject | ReferenceObject ) [ ] ,
144
154
required ?: string [ ] ,
145
155
) : ts . TypeNode [ ] {
@@ -184,6 +194,7 @@ export function transformSchemaObjectWithComposition(
184
194
options ,
185
195
) ;
186
196
}
197
+
187
198
const discriminator =
188
199
( "$ref" in item && options . ctx . discriminators . objects [ item . $ref ] ) ||
189
200
( item as any ) . discriminator ; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -201,7 +212,7 @@ export function transformSchemaObjectWithComposition(
201
212
202
213
// core + allOf: intersect
203
214
const coreObjectType = transformSchemaObjectCore ( schemaObject , options ) ;
204
- const allOfType = collectCompositions (
215
+ const allOfType = collectAllOfCompositions (
205
216
schemaObject . allOf ?? [ ] ,
206
217
schemaObject . required ,
207
218
) ;
@@ -216,21 +227,17 @@ export function transformSchemaObjectWithComposition(
216
227
}
217
228
// anyOf: union
218
229
// (note: this may seem counterintuitive, but as TypeScript’s unions are not true XORs, they mimic behavior closer to anyOf than oneOf)
219
- const anyOfType = collectCompositions (
220
- schemaObject . anyOf ?? [ ] ,
221
- schemaObject . required ,
222
- ) ;
230
+ const anyOfType = collectUnionCompositions ( schemaObject . anyOf ?? [ ] ) ;
223
231
if ( anyOfType . length ) {
224
232
finalType = tsUnion ( [ ...( finalType ? [ finalType ] : [ ] ) , ...anyOfType ] ) ;
225
233
}
226
234
// oneOf: union (within intersection with other types, if any)
227
- const oneOfType = collectCompositions (
235
+ const oneOfType = collectUnionCompositions (
228
236
schemaObject . oneOf ||
229
237
( "type" in schemaObject &&
230
238
schemaObject . type === "object" &&
231
239
( schemaObject . enum as ( SchemaObject | ReferenceObject ) [ ] ) ) ||
232
240
[ ] ,
233
- schemaObject . required ,
234
241
) ;
235
242
if ( oneOfType . length ) {
236
243
// note: oneOf is the only type that may include primitives
@@ -408,8 +415,8 @@ function transformSchemaObjectCore(
408
415
// type: object
409
416
const coreObjectType : ts . TypeElement [ ] = [ ] ;
410
417
411
- // discriminatorss : explicit mapping on schema object
412
- for ( const k of [ "oneOf" , " allOf", "anyOf" ] as const ) {
418
+ // discriminators : explicit mapping on schema object
419
+ for ( const k of [ "allOf" , "anyOf" ] as const ) {
413
420
if ( ! schemaObject [ k ] ) {
414
421
continue ;
415
422
}
0 commit comments