Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-suits-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': patch
---

fix: fix translateChineseModuleNodeToEnglish not support includeTags
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty, map } from 'lodash';
import { isEmpty, isObject, isString, map } from 'lodash';

import { PriorityRule, ReactQueryMode } from './config';
import type { TypescriptFileType } from './generator/config';
Expand Down Expand Up @@ -301,7 +301,13 @@ export async function generateService({
}

if (isTranslateToEnglishTag) {
await translateChineseModuleNodeToEnglish(openAPI);
const res = await translateChineseModuleNodeToEnglish(openAPI);

if (isObject(res) && !isEmpty(includeTags)) {
includeTags = map(includeTags, (item) => {
return isString(item) ? res[item] || item : item;
});
}
}

const requestImportStatement = getImportStatement(requestLibPath);
Expand All @@ -314,28 +320,28 @@ export async function generateService({
priorityRule,
includeTags: includeTags
? map(includeTags, (item) =>
typeof item === 'string' ? item.toLowerCase() : item
isString(item) ? item.toLowerCase() : item
)
: priorityRule === PriorityRule.include ||
priorityRule === PriorityRule.both
? [/.*/g]
: null,
includePaths: includePaths
? map(includePaths, (item) =>
typeof item === 'string' ? item.toLowerCase() : item
isString(item) ? item.toLowerCase() : item
)
: priorityRule === PriorityRule.include ||
priorityRule === PriorityRule.both
? [/.*/g]
: null,
excludeTags: excludeTags
? map(excludeTags, (item) =>
typeof item === 'string' ? item.toLowerCase() : item
isString(item) ? item.toLowerCase() : item
)
: null,
excludePaths: excludePaths
? map(excludePaths, (item) =>
typeof item === 'string' ? item.toLowerCase() : item
isString(item) ? item.toLowerCase() : item
)
: null,
requestOptionsType: '{[key: string]: unknown}',
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function isJSONString(str: string) {
export async function translateChineseModuleNodeToEnglish(
openAPI: OpenAPIObject
) {
return new Promise((resolve, reject) => {
return new Promise<Record<string, string> | boolean>((resolve, reject) => {
const translateMap: Record<string, string> = {};
const operations = [] as OperationObject[];
let tags: string[] = [];
Expand Down Expand Up @@ -308,7 +308,7 @@ export async function translateChineseModuleNodeToEnglish(
}
});
});
resolve(true);
resolve(translateMap);
})
.catch(() => {
reject(false);
Expand Down