File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,11 @@ export function tsArrayOf(type: string): string {
105105 return `(${ type } )[]` ;
106106}
107107
108+ /** Convert array of types into [T, A, B, ...] */
109+ export function tsTupleOf ( types : string [ ] ) : string {
110+ return `[${ types . join ( ", " ) } ]` ;
111+ }
112+
108113/** Convert T, U into T & U; */
109114export function tsIntersectionOf ( types : string [ ] ) : string {
110115 return `(${ types . join ( ") & (" ) } )` ;
Original file line number Diff line number Diff line change 88 tsIntersectionOf ,
99 tsPartial ,
1010 tsUnionOf ,
11+ tsTupleOf ,
1112} from "./utils" ;
1213
1314export const PRIMITIVES : { [ key : string ] : "boolean" | "string" | "number" } = {
@@ -92,7 +93,11 @@ export default function generateTypesV3(
9293 ] ) ;
9394 }
9495 case "array" : {
95- return tsArrayOf ( transform ( node . items as any ) ) ;
96+ if ( Array . isArray ( node . items ) ) {
97+ return tsTupleOf ( node . items . map ( transform ) ) ;
98+ } else {
99+ return tsArrayOf ( transform ( node . items as any ) ) ;
100+ }
96101 }
97102 }
98103
Original file line number Diff line number Diff line change @@ -210,6 +210,13 @@ describe("types", () => {
210210 inferred_array : {
211211 items : { $ref : "#/components/schemas/array" } ,
212212 } ,
213+ tuple : {
214+ type : "array" ,
215+ items : [
216+ { type : "string" } ,
217+ { type : "number" }
218+ ]
219+ } ,
213220 nullable : {
214221 type : "array" ,
215222 items : { type : "string" } ,
@@ -232,6 +239,7 @@ describe("types", () => {
232239 string: string;
233240 array_ref: components['schemas']['array'][];
234241 inferred_array: components['schemas']['array'][];
242+ tuple: [string, number];
235243 nullable: string[] | null;
236244 }
237245 }` )
You can’t perform that action at this time.
0 commit comments