Skip to content

Commit 57d746c

Browse files
committed
fix type errors
1 parent 926c989 commit 57d746c

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/scripts/generate-sdk.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@ import { kill } from "node:process";
66
const ENGINE_OPENAPI_URL = "http://localhost:3005/json";
77
const REPLACE_LOG_FILE = "sdk/replacement_log.txt";
88

9+
type BasicOpenAPISpec = {
10+
paths?: {
11+
[path: string]: {
12+
[method: string]: {
13+
operationId?: string;
14+
};
15+
};
16+
};
17+
};
18+
919
function generateOperationIdMappings(
10-
oldSpec: any,
11-
newSpec: any,
20+
oldSpec: BasicOpenAPISpec,
21+
newSpec: BasicOpenAPISpec,
1222
): Record<string, string> {
1323
const mappings: Record<string, string> = {};
1424

15-
for (const [path, methods] of Object.entries(newSpec.paths)) {
16-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
17-
for (const [method, details] of Object.entries(methods as any)) {
18-
if (details.operationId && oldSpec.paths[path]?.[method]?.operationId) {
19-
const newId = details.operationId;
20-
const oldId = oldSpec.paths[path][method].operationId;
21-
if (newId !== oldId) {
22-
mappings[newId] = oldId;
25+
if (newSpec.paths && oldSpec.paths) {
26+
for (const [path, pathItem] of Object.entries(newSpec.paths)) {
27+
for (const [method, operation] of Object.entries(pathItem)) {
28+
const oldOperation = oldSpec.paths[path]?.[method];
29+
if (
30+
operation.operationId &&
31+
oldOperation?.operationId &&
32+
operation.operationId !== oldOperation.operationId
33+
) {
34+
mappings[operation.operationId] = oldOperation.operationId;
2335
}
2436
}
2537
}
@@ -101,7 +113,10 @@ async function main(): Promise<void> {
101113

102114
fs.writeFileSync("openapi.json", JSON.stringify(newSpec, null, 2), "utf-8");
103115

104-
const operationIdMappings = generateOperationIdMappings(oldSpec, newSpec);
116+
const operationIdMappings = generateOperationIdMappings(
117+
oldSpec,
118+
newSpec as BasicOpenAPISpec,
119+
);
105120

106121
execSync(
107122
"yarn openapi --input ./openapi.json --output ./sdk/src --name Engine",

0 commit comments

Comments
 (0)