Skip to content

Commit c2441b3

Browse files
committed
feat: 新增配置项 unwrapResponseData
1 parent ab33280 commit c2441b3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/configure.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const defaults: Config = {
55
cwd: process.cwd(),
66
dest: 'src/apis',
77
axiosImport: axiosImportDefault,
8+
unwrapResponseData: false,
89
list: [],
910
};
1011

src/generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { exitError, normalizeError, tryCatch } from './utils';
99

1010
export async function generateItem(oas: Oas, config: Config) {
1111
const { name, url, spec, axiosImport: axiosImportScope } = oas;
12-
const { cwd, dest, axiosImport: axiosImportGlobal } = config;
12+
const { cwd, dest, axiosImport: axiosImportGlobal, unwrapResponseData } = config;
1313
const axiosImport = axiosImportScope || axiosImportGlobal || axiosImportDefault;
1414
const { files } = await generateApi({
1515
name,
@@ -19,6 +19,7 @@ export async function generateItem(oas: Oas, config: Config) {
1919
httpClientType: 'axios',
2020
templates: templatesDir,
2121
silent: true,
22+
unwrapResponseData,
2223
});
2324

2425
for (const { content, name: filename } of files) {

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export interface UserConfig {
3939
*/
4040
axiosImport?: string;
4141

42+
/**
43+
* 是否取消包装 data,默认 false
44+
* false = 返回值就是响应(response),response.data 才是实际值
45+
* true = 返回值就是数据
46+
* @default false
47+
*/
48+
unwrapResponseData?: boolean;
49+
4250
/**
4351
* oas 列表
4452
*/

0 commit comments

Comments
 (0)