@@ -50,6 +50,8 @@ export default function generateTypesV3(
50
50
}
51
51
}
52
52
53
+ const operations : Record < string , OpenAPI3Operation > = { } ;
54
+
53
55
// propertyMapper
54
56
const propertyMapped = options
55
57
? propertyMapper ( components . schemas , options . propertyMapper )
@@ -211,13 +213,9 @@ export default function generateTypesV3(
211
213
return output ;
212
214
}
213
215
214
- function transformOperation (
215
- method : string ,
216
- operation : OpenAPI3Operation
217
- ) : string {
216
+ function transformOperation ( operation : OpenAPI3Operation ) : string {
218
217
let output = "" ;
219
- if ( operation . description ) output += comment ( operation . description ) ;
220
- output += `"${ method } ": {\n` ;
218
+ output += `{\n` ;
221
219
222
220
// handle operation parameters
223
221
if ( operation . parameters ) {
@@ -269,7 +267,17 @@ export default function generateTypesV3(
269
267
Object . entries ( methods ) . forEach ( ( [ method , operation ] ) => {
270
268
// skip the parameters "method" for shared parameters - we'll handle it later
271
269
if ( method !== "parameters" ) {
272
- output += transformOperation ( method , operation as OpenAPI3Operation ) ;
270
+ operation = operation as OpenAPI3Operation ;
271
+
272
+ if ( operation . operationId ) {
273
+ output += `"${ method } ": operations["${ operation . operationId } "];\n` ;
274
+ operations [ operation . operationId ] = operation ;
275
+ } else {
276
+ if ( operation . description ) output += comment ( operation . description ) ;
277
+ output += `"${ method } ": ${ transformOperation (
278
+ operation as OpenAPI3Operation
279
+ ) } `;
280
+ }
273
281
}
274
282
} ) ;
275
283
@@ -300,6 +308,16 @@ export default function generateTypesV3(
300
308
` ;
301
309
}
302
310
311
+ finalOutput += "export interface operations {\n" ;
312
+ for ( const [ operationId , operation ] of Object . entries ( operations ) ) {
313
+ if ( operation . description ) finalOutput += comment ( operation . description ) ;
314
+ finalOutput += `"${ operationId } ": ${ transformOperation (
315
+ operation as OpenAPI3Operation
316
+ ) } `;
317
+ }
318
+ // close operations wrapper
319
+ finalOutput += "\n}\n\n" ;
320
+
303
321
finalOutput += "export interface components {\n" ;
304
322
305
323
if ( components . parameters && Object . keys ( components . parameters ) . length ) {
0 commit comments