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 {
105
105
return `(${ type } )[]` ;
106
106
}
107
107
108
+ /** Convert array of types into [T, A, B, ...] */
109
+ export function tsTupleOf ( types : string [ ] ) : string {
110
+ return `[${ types . join ( ", " ) } ]` ;
111
+ }
112
+
108
113
/** Convert T, U into T & U; */
109
114
export function tsIntersectionOf ( types : string [ ] ) : string {
110
115
return `(${ types . join ( ") & (" ) } )` ;
Original file line number Diff line number Diff line change 8
8
tsIntersectionOf ,
9
9
tsPartial ,
10
10
tsUnionOf ,
11
+ tsTupleOf ,
11
12
} from "./utils" ;
12
13
13
14
export const PRIMITIVES : { [ key : string ] : "boolean" | "string" | "number" } = {
@@ -92,7 +93,11 @@ export default function generateTypesV3(
92
93
] ) ;
93
94
}
94
95
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
+ }
96
101
}
97
102
}
98
103
Original file line number Diff line number Diff line change @@ -210,6 +210,13 @@ describe("types", () => {
210
210
inferred_array : {
211
211
items : { $ref : "#/components/schemas/array" } ,
212
212
} ,
213
+ tuple : {
214
+ type : "array" ,
215
+ items : [
216
+ { type : "string" } ,
217
+ { type : "number" }
218
+ ]
219
+ } ,
213
220
nullable : {
214
221
type : "array" ,
215
222
items : { type : "string" } ,
@@ -232,6 +239,7 @@ describe("types", () => {
232
239
string: string;
233
240
array_ref: components['schemas']['array'][];
234
241
inferred_array: components['schemas']['array'][];
242
+ tuple: [string, number];
235
243
nullable: string[] | null;
236
244
}
237
245
}` )
You can’t perform that action at this time.
0 commit comments