Skip to content

Commit 4d6b16f

Browse files
committed
fix(openapi-typescript):transformSchemaObject support two-dimensional array
1 parent 310971d commit 4d6b16f

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

packages/openapi-typescript/src/transform/schema-object.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ function transformSchemaObjectCore(
302302
}
303303
// standard array type
304304
else if (schemaObject.items) {
305-
itemType = transformSchemaObject(schemaObject.items, options);
305+
if("type" in schemaObject.items && schemaObject.items.type === 'array'){
306+
itemType = ts.factory.createArrayTypeNode(transformSchemaObject(schemaObject.items, options));
307+
} else {
308+
itemType = transformSchemaObject(schemaObject.items, options);
309+
}
306310
}
307311

308312
const min: number =
@@ -350,9 +354,9 @@ function transformSchemaObjectCore(
350354
}
351355
}
352356

353-
return ts.isTupleTypeNode(itemType)
357+
return ts.isTupleTypeNode(itemType) || ts.isArrayTypeNode(itemType)
354358
? itemType
355-
: ts.factory.createArrayTypeNode(itemType); // wrap itemType in array type, but only if not a tuple already
359+
: ts.factory.createArrayTypeNode(itemType); // wrap itemType in array type, but only if not a tuple or array already
356360
}
357361

358362
// polymorphic, or 3.1 nullable

packages/openapi-typescript/test/transform/schema-object/object.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,42 @@ describe("transformSchemaObject > object", () => {
337337
},
338338
},
339339
],
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+
],
340376
];
341377

342378
for (const [

0 commit comments

Comments
 (0)