Skip to content

Commit deebf04

Browse files
committed
fix(generate): preserve SDK v3 method aliases in type generation
Update OpenAPI type generation script to automatically add SDK v3 method name aliases to the operations interface. This ensures aliases persist through automated OpenAPI syncs and maintain TypeScript compatibility.
1 parent c828fa8 commit deebf04

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

scripts/generate-sdk.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ async function generateTypes() {
5353
writeFileSync(typesPath, output, 'utf8')
5454
// Fix array syntax after writing to disk
5555
fixArraySyntax(typesPath)
56+
// Add SDK v3 method name aliases
57+
addSdkMethodAliases(typesPath)
5658
resolve()
5759
} catch (error) {
5860
reject(error)
@@ -63,6 +65,46 @@ async function generateTypes() {
6365
})
6466
}
6567

68+
/**
69+
* Adds SDK v3 method name aliases to the operations interface.
70+
* These aliases map the new SDK method names to their underlying OpenAPI operation names.
71+
* @param {string} filePath - The path to the TypeScript file to update
72+
*/
73+
function addSdkMethodAliases(filePath) {
74+
const content = readFileSync(filePath, 'utf8')
75+
76+
// Find the closing brace of the operations interface
77+
const operationsInterfaceEnd = content.lastIndexOf('\n}')
78+
79+
if (operationsInterfaceEnd === -1) {
80+
logger.error(' Could not find operations interface closing brace')
81+
return
82+
}
83+
84+
const aliases = ` // SDK v3 method name aliases for TypeScript compatibility.
85+
// These map the new SDK method names to their underlying OpenAPI operation names.
86+
listOrganizations: operations['getOrganizations']
87+
listRepositories: operations['getOrgRepoList']
88+
createRepository: operations['createOrgRepo']
89+
deleteRepository: operations['deleteOrgRepo']
90+
updateRepository: operations['updateOrgRepo']
91+
getRepository: operations['getOrgRepo']
92+
listFullScans: operations['getOrgFullScanList']
93+
createFullScan: operations['CreateOrgFullScan']
94+
getFullScan: operations['getOrgFullScan']
95+
streamFullScan: operations['getOrgFullScan']
96+
deleteFullScan: operations['deleteOrgFullScan']
97+
getFullScanMetadata: operations['getOrgFullScanMetadata']
98+
`
99+
100+
const updated =
101+
content.slice(0, operationsInterfaceEnd) +
102+
aliases +
103+
content.slice(operationsInterfaceEnd)
104+
writeFileSync(filePath, updated, 'utf8')
105+
logger.log(' Added SDK v3 method name aliases')
106+
}
107+
66108
/**
67109
* Fixes array syntax to comply with ESLint array-simple rules.
68110
* Simple types (string, number, boolean) use T[] syntax.

0 commit comments

Comments
 (0)