Skip to content

Commit 31ebf30

Browse files
committed
fix: 修正请求参数键名错误的问题
1 parent 10110d4 commit 31ebf30

File tree

9 files changed

+329
-274
lines changed

9 files changed

+329
-274
lines changed

src/printer/Args.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ArgItem } from './Arg';
22
import { requiredTypeStringify } from './helpers';
3-
import { Named } from './Named';
43

54
export class Args {
65
fixedArgs: ArgItem[];
@@ -45,7 +44,7 @@ export class Args {
4544

4645
if (kind === 'config') return `...${uniqueName}`;
4746

48-
const propVal = arg.structured ? `{${originName}:${uniqueName}}` : uniqueName;
47+
const value = arg.structured ? (originName === uniqueName ? `{${originName}}` : `{${originName}: ${uniqueName}}`) : uniqueName;
4948

5049
if (kind === 'path') {
5150
const args = [
@@ -54,12 +53,12 @@ export class Args {
5453
JSON.stringify(url),
5554
];
5655

57-
if (type !== '') args.push(propVal);
56+
if (type !== '') args.push(value);
5857

59-
return `url:resolveURL(${args.join(',')})`;
58+
return `url: resolveURL(${args.join(',')})`;
6059
}
6160

62-
return `${originName}:${propVal}`;
61+
return kind === value ? kind : `${kind}: ${value}`;
6362
})
6463
.join(',\n');
6564
}

src/printer/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ export class Printer {
270270
const { axiosRequestConfigTypeName = AXIOS_QUEST_CONFIG_TYPE_NAME } = this.options || {};
271271

272272
return `${jsDoc.print()}
273-
export async function ${funcName}(${requestArgs.toArgs(axiosRequestConfigTypeName)}): AxiosPromise<${respType}> {
274-
return axios({
275-
method: ${JSON.stringify(method)},
276-
${requestArgs.toValues(url)}
277-
});
278-
}`;
273+
export async function ${funcName}(${requestArgs.toArgs(axiosRequestConfigTypeName)}): AxiosPromise<${respType}> {
274+
return axios({
275+
method: ${JSON.stringify(method)},
276+
${requestArgs.toValues(url)}
277+
});
278+
}`;
279279
}
280280

281281
private _parseContents(

0 commit comments

Comments
 (0)