Skip to content

Commit

Permalink
fix: 修正请求参数键名错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jul 22, 2024
1 parent 10110d4 commit 31ebf30
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 274 deletions.
9 changes: 4 additions & 5 deletions src/printer/Args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ArgItem } from './Arg';
import { requiredTypeStringify } from './helpers';
import { Named } from './Named';

export class Args {
fixedArgs: ArgItem[];
Expand Down Expand Up @@ -45,7 +44,7 @@ export class Args {

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

const propVal = arg.structured ? `{${originName}:${uniqueName}}` : uniqueName;
const value = arg.structured ? (originName === uniqueName ? `{${originName}}` : `{${originName}: ${uniqueName}}`) : uniqueName;

if (kind === 'path') {
const args = [
Expand All @@ -54,12 +53,12 @@ export class Args {
JSON.stringify(url),
];

if (type !== '') args.push(propVal);
if (type !== '') args.push(value);

return `url:resolveURL(${args.join(',')})`;
return `url: resolveURL(${args.join(',')})`;
}

return `${originName}:${propVal}`;
return kind === value ? kind : `${kind}: ${value}`;
})
.join(',\n');
}
Expand Down
12 changes: 6 additions & 6 deletions src/printer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ export class Printer {
const { axiosRequestConfigTypeName = AXIOS_QUEST_CONFIG_TYPE_NAME } = this.options || {};

return `${jsDoc.print()}
export async function ${funcName}(${requestArgs.toArgs(axiosRequestConfigTypeName)}): AxiosPromise<${respType}> {
return axios({
method: ${JSON.stringify(method)},
${requestArgs.toValues(url)}
});
}`;
export async function ${funcName}(${requestArgs.toArgs(axiosRequestConfigTypeName)}): AxiosPromise<${respType}> {
return axios({
method: ${JSON.stringify(method)},
${requestArgs.toValues(url)}
});
}`;
}

private _parseContents(
Expand Down
Loading

0 comments on commit 31ebf30

Please sign in to comment.