@@ -50,6 +50,8 @@ export default function generateTypesV3(
5050 }
5151 }
5252
53+ const operations : Record < string , OpenAPI3Operation > = { } ;
54+
5355 // propertyMapper
5456 const propertyMapped = options
5557 ? propertyMapper ( components . schemas , options . propertyMapper )
@@ -211,13 +213,9 @@ export default function generateTypesV3(
211213 return output ;
212214 }
213215
214- function transformOperation (
215- method : string ,
216- operation : OpenAPI3Operation
217- ) : string {
216+ function transformOperation ( operation : OpenAPI3Operation ) : string {
218217 let output = "" ;
219- if ( operation . description ) output += comment ( operation . description ) ;
220- output += `"${ method } ": {\n` ;
218+ output += `{\n` ;
221219
222220 // handle operation parameters
223221 if ( operation . parameters ) {
@@ -269,7 +267,17 @@ export default function generateTypesV3(
269267 Object . entries ( methods ) . forEach ( ( [ method , operation ] ) => {
270268 // skip the parameters "method" for shared parameters - we'll handle it later
271269 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+ }
273281 }
274282 } ) ;
275283
@@ -300,6 +308,16 @@ export default function generateTypesV3(
300308` ;
301309 }
302310
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+
303321 finalOutput += "export interface components {\n" ;
304322
305323 if ( components . parameters && Object . keys ( components . parameters ) . length ) {
0 commit comments