Skip to content

Commit 386497f

Browse files
fix(codegen): axios query
1 parent bcdc1d1 commit 386497f

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

src/templates/core/axios/request.hbs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,7 @@ import type { OpenAPIConfig } from './OpenAPI';
5858

5959
{{>functions/catchErrorCodes}}
6060

61-
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
62-
const encoder = config.ENCODE_PATH || encodeURI;
63-
64-
const path = options.url
65-
.replace('{api-version}', config.VERSION)
66-
.replace(/{(.*?)}/g, (substring: string, group: string) => {
67-
if (options.path?.hasOwnProperty(group)) {
68-
return encoder(String(options.path[group]));
69-
}
70-
return substring;
71-
});
72-
73-
const url = `${config.BASE}${path}`;
74-
75-
return url;
76-
};
61+
{{>functions/getUrl}}
7762

7863

7964
/**
@@ -87,7 +72,7 @@ const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
8772
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, axiosClient: AxiosInstance = axios): CancelablePromise<T> => {
8873
return new CancelablePromise(async (resolve, reject, onCancel) => {
8974
try {
90-
const url = getUrl(config, options);
75+
const url = getUrl(config, { ...options, query: undefined });
9176
const formData = getFormData(options);
9277
const body = getRequestBody(options);
9378
const headers = await getHeaders(config, options, formData);

src/templates/core/functions/getQueryString.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const getQueryString = (params: Record<string, any>): string => {
88
const process = (key: string, value: any) => {
99
if (isDefined(value)) {
1010
if (Array.isArray(value)) {
11-
value.forEach(v => {
12-
process(key, v);
11+
value.forEach((v, i) => {
12+
process(`${key}[${i}]`, v);
1313
});
1414
} else if (typeof value === 'object') {
1515
Object.entries(value).forEach(([k, v]) => {

0 commit comments

Comments
 (0)