Skip to content

Commit b1426e5

Browse files
Merge pull request #412 from openapi-ui/fix/fix-translate-tag
fix: fix translateChineseModuleNodeToEnglish not support includeTags
2 parents 9cecace + 4443208 commit b1426e5

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

.changeset/old-suits-itch.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 translateChineseModuleNodeToEnglish not support includeTags

src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEmpty, map } from 'lodash';
1+
import { isEmpty, isObject, isString, map } from 'lodash';
22

33
import { PriorityRule, ReactQueryMode } from './config';
44
import type { TypescriptFileType } from './generator/config';
@@ -301,7 +301,13 @@ export async function generateService({
301301
}
302302

303303
if (isTranslateToEnglishTag) {
304-
await translateChineseModuleNodeToEnglish(openAPI);
304+
const res = await translateChineseModuleNodeToEnglish(openAPI);
305+
306+
if (isObject(res) && !isEmpty(includeTags)) {
307+
includeTags = map(includeTags, (item) => {
308+
return isString(item) ? res[item] || item : item;
309+
});
310+
}
305311
}
306312

307313
const requestImportStatement = getImportStatement(requestLibPath);
@@ -314,28 +320,28 @@ export async function generateService({
314320
priorityRule,
315321
includeTags: includeTags
316322
? map(includeTags, (item) =>
317-
typeof item === 'string' ? item.toLowerCase() : item
323+
isString(item) ? item.toLowerCase() : item
318324
)
319325
: priorityRule === PriorityRule.include ||
320326
priorityRule === PriorityRule.both
321327
? [/.*/g]
322328
: null,
323329
includePaths: includePaths
324330
? map(includePaths, (item) =>
325-
typeof item === 'string' ? item.toLowerCase() : item
331+
isString(item) ? item.toLowerCase() : item
326332
)
327333
: priorityRule === PriorityRule.include ||
328334
priorityRule === PriorityRule.both
329335
? [/.*/g]
330336
: null,
331337
excludeTags: excludeTags
332338
? map(excludeTags, (item) =>
333-
typeof item === 'string' ? item.toLowerCase() : item
339+
isString(item) ? item.toLowerCase() : item
334340
)
335341
: null,
336342
excludePaths: excludePaths
337343
? map(excludePaths, (item) =>
338-
typeof item === 'string' ? item.toLowerCase() : item
344+
isString(item) ? item.toLowerCase() : item
339345
)
340346
: null,
341347
requestOptionsType: '{[key: string]: unknown}',

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function isJSONString(str: string) {
261261
export async function translateChineseModuleNodeToEnglish(
262262
openAPI: OpenAPIObject
263263
) {
264-
return new Promise((resolve, reject) => {
264+
return new Promise<Record<string, string> | boolean>((resolve, reject) => {
265265
const translateMap: Record<string, string> = {};
266266
const operations = [] as OperationObject[];
267267
let tags: string[] = [];
@@ -308,7 +308,7 @@ export async function translateChineseModuleNodeToEnglish(
308308
}
309309
});
310310
});
311-
resolve(true);
311+
resolve(translateMap);
312312
})
313313
.catch(() => {
314314
reject(false);

0 commit comments

Comments
 (0)