Skip to content

Commit 4314762

Browse files
Merge pull request #646 from openapi-ui/main
chore: merge main to release
2 parents a9ffbb8 + a53efd7 commit 4314762

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

.changeset/silent-badgers-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
fix: fix bug #644

src/util.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,23 @@ export async function translateChineseModuleNodeToEnglish(
326326
});
327327
});
328328
resolve(translateMap);
329+
330+
// 在写入前再次读取缓存,合并多个任务的翻译结果
331+
const existingContent = readFileSafelySync(
332+
process.cwd() + '/openapi-ts-request.cache.json'
333+
);
334+
let existingCache: Record<string, string> = {};
335+
336+
if (existingContent !== null && isJSONString(existingContent)) {
337+
existingCache = JSON.parse(existingContent) as Record<string, string>;
338+
}
339+
340+
// 合并现有缓存和新的翻译结果(新结果优先)
341+
const mergedCache = { ...existingCache, ...translateMap };
342+
329343
void writeFileAsync(
330344
process.cwd() + '/openapi-ts-request.cache.json',
331-
JSON.stringify(translateMap, null, 2)
345+
JSON.stringify(mergedCache, null, 2)
332346
);
333347
})
334348
.catch(() => {

0 commit comments

Comments
 (0)