File tree 2 files changed +48
-3
lines changed
packages/openapi-typescript
test/transform/schema-object
2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -302,7 +302,16 @@ function transformSchemaObjectCore(
302
302
}
303
303
// standard array type
304
304
else if ( schemaObject . items ) {
305
- itemType = transformSchemaObject ( schemaObject . items , options ) ;
305
+ if (
306
+ "type" in schemaObject . items &&
307
+ schemaObject . items . type === "array"
308
+ ) {
309
+ itemType = ts . factory . createArrayTypeNode (
310
+ transformSchemaObject ( schemaObject . items , options ) ,
311
+ ) ;
312
+ } else {
313
+ itemType = transformSchemaObject ( schemaObject . items , options ) ;
314
+ }
306
315
}
307
316
308
317
const min : number =
@@ -350,9 +359,9 @@ function transformSchemaObjectCore(
350
359
}
351
360
}
352
361
353
- return ts . isTupleTypeNode ( itemType )
362
+ return ts . isTupleTypeNode ( itemType ) || ts . isArrayTypeNode ( itemType )
354
363
? itemType
355
- : ts . factory . createArrayTypeNode ( itemType ) ; // wrap itemType in array type, but only if not a tuple already
364
+ : ts . factory . createArrayTypeNode ( itemType ) ; // wrap itemType in array type, but only if not a tuple or array already
356
365
}
357
366
358
367
// polymorphic, or 3.1 nullable
Original file line number Diff line number Diff line change @@ -337,6 +337,42 @@ describe("transformSchemaObject > object", () => {
337
337
} ,
338
338
} ,
339
339
] ,
340
+ [
341
+ "options > two-dimensional array" ,
342
+ {
343
+ given : {
344
+ type : "object" ,
345
+ properties : {
346
+ array : {
347
+ type : "array" ,
348
+ items : {
349
+ items : [
350
+ {
351
+ type : "string" ,
352
+ } ,
353
+ {
354
+ type : "boolean" ,
355
+ } ,
356
+ ] ,
357
+ type : "array" ,
358
+ maxItems : 2 ,
359
+ minItems : 2 ,
360
+ } ,
361
+ } ,
362
+ } ,
363
+ } ,
364
+ want : `{
365
+ array?: [
366
+ string,
367
+ boolean
368
+ ][];
369
+ }` ,
370
+ options : {
371
+ ...DEFAULT_OPTIONS ,
372
+ ctx : { ...DEFAULT_OPTIONS . ctx } ,
373
+ } ,
374
+ } ,
375
+ ] ,
340
376
] ;
341
377
342
378
for ( const [
You can’t perform that action at this time.
0 commit comments