Skip to content

Commit 1694a9b

Browse files
committed
change: Use default Axios serialization.
1 parent 14eaccb commit 1694a9b

File tree

4 files changed

+5
-27
lines changed

4 files changed

+5
-27
lines changed

src/templates/core/axios/getHeaders.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
1+
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Record<string, string>> => {
22
const token = await resolve(options, config.TOKEN);
33
const username = await resolve(options, config.USERNAME);
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);
6-
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {}
76

87
const headers = Object.entries({
98
Accept: 'application/json',
109
...additionalHeaders,
1110
...options.headers,
12-
...formHeaders,
1311
})
1412
.filter(([_, value]) => isDefined(value))
1513
.reduce((headers, [key, value]) => ({

src/templates/core/axios/request.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, ax
7676
const url = getUrl(config, options);
7777
const formData = getFormData(options);
7878
const body = getRequestBody(options);
79-
const headers = await getHeaders(config, options, formData);
79+
const headers = await getHeaders(config, options);
8080

8181
if (!onCancel.isCancelled) {
8282
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);

src/templates/core/axios/sendRequest.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const sendRequest = async <T>(
33
options: ApiRequestOptions,
44
url: string,
55
body: any,
6-
formData: FormData | undefined,
6+
formData: Record<string, string> | undefined,
77
headers: Record<string, string>,
88
onCancel: OnCancel,
99
axiosClient: AxiosInstance
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
1+
export const getFormData = (options: ApiRequestOptions): Record<string, any> | undefined => {
22
if (options.formData) {
3-
const formData = new FormData();
4-
5-
const process = (key: string, value: any) => {
6-
if (isString(value) || isBlob(value)) {
7-
formData.append(key, value);
8-
} else {
9-
formData.append(key, JSON.stringify(value));
10-
}
11-
};
12-
13-
Object.entries(options.formData)
14-
.filter(([_, value]) => isDefined(value))
15-
.forEach(([key, value]) => {
16-
if (Array.isArray(value)) {
17-
value.forEach(v => process(key, v));
18-
} else {
19-
process(key, value);
20-
}
21-
});
22-
23-
return formData;
3+
return options.formData;
244
}
255
return undefined;
266
};

0 commit comments

Comments
 (0)