Skip to content

Commit bcdc1d1

Browse files
fix(codegen): axios query bug
1 parent e1a512d commit bcdc1d1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/templates/core/axios/request.hbs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ import type { OpenAPIConfig } from './OpenAPI';
3535
{{>functions/getQueryString}}
3636

3737

38-
{{>functions/getUrl}}
39-
40-
4138
{{>functions/getFormData}}
4239

4340

@@ -61,6 +58,23 @@ import type { OpenAPIConfig } from './OpenAPI';
6158

6259
{{>functions/catchErrorCodes}}
6360

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+
};
77+
6478

6579
/**
6680
* Request method

src/templates/core/axios/sendRequest.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const sendRequest = async <T>(
1515
headers,
1616
data: body ?? formData,
1717
method: options.method,
18+
params: options.query,
1819
withCredentials: config.WITH_CREDENTIALS,
1920
withXSRFToken: config.CREDENTIALS === 'include' ? config.WITH_CREDENTIALS : false,
2021
cancelToken: source.token,

0 commit comments

Comments
 (0)