diff --git a/.changeset/old-suits-itch.md b/.changeset/old-suits-itch.md new file mode 100644 index 0000000..fd5e610 --- /dev/null +++ b/.changeset/old-suits-itch.md @@ -0,0 +1,5 @@ +--- +'openapi-ts-request': patch +--- + +fix: fix translateChineseModuleNodeToEnglish not support includeTags diff --git a/src/index.ts b/src/index.ts index 6975ca9..191ef4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -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); @@ -314,7 +320,7 @@ 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 @@ -322,7 +328,7 @@ export async function generateService({ : null, includePaths: includePaths ? map(includePaths, (item) => - typeof item === 'string' ? item.toLowerCase() : item + isString(item) ? item.toLowerCase() : item ) : priorityRule === PriorityRule.include || priorityRule === PriorityRule.both @@ -330,12 +336,12 @@ export async function generateService({ : 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}', diff --git a/src/util.ts b/src/util.ts index cc19b1f..90a92d9 100644 --- a/src/util.ts +++ b/src/util.ts @@ -261,7 +261,7 @@ function isJSONString(str: string) { export async function translateChineseModuleNodeToEnglish( openAPI: OpenAPIObject ) { - return new Promise((resolve, reject) => { + return new Promise | boolean>((resolve, reject) => { const translateMap: Record = {}; const operations = [] as OperationObject[]; let tags: string[] = []; @@ -308,7 +308,7 @@ export async function translateChineseModuleNodeToEnglish( } }); }); - resolve(true); + resolve(translateMap); }) .catch(() => { reject(false);