diff --git a/.changeset/red-rings-walk.md b/.changeset/red-rings-walk.md new file mode 100644 index 0000000000..5e61c37fe9 --- /dev/null +++ b/.changeset/red-rings-walk.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix(axios): set content type to multipart/form-data when using form data diff --git a/src/templates/core/axios/getHeaders.hbs b/src/templates/core/axios/getHeaders.hbs index a2386d30f2..44eb7c8602 100644 --- a/src/templates/core/axios/getHeaders.hbs +++ b/src/templates/core/axios/getHeaders.hbs @@ -36,6 +36,8 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio } else if (!isFormData(options.body)) { headers['Content-Type'] = 'application/json'; } + } else if (options.formData !== undefined) { + headers['Content-Type'] = options.mediaType; } return headers; diff --git a/test/__snapshots__/v3_axios/core/request.ts.snap b/test/__snapshots__/v3_axios/core/request.ts.snap index 3958de2afd..d0d546b347 100644 --- a/test/__snapshots__/v3_axios/core/request.ts.snap +++ b/test/__snapshots__/v3_axios/core/request.ts.snap @@ -132,6 +132,8 @@ export const getHeaders = async ( } else if (!isFormData(options.body)) { headers['Content-Type'] = 'application/json'; } + } else if (options.formData !== undefined) { + headers['Content-Type'] = options.mediaType; } return headers;