diff --git a/src/templates/core/axios/getHeaders.hbs b/src/templates/core/axios/getHeaders.hbs index 8977a5f1..e8a4afa3 100644 --- a/src/templates/core/axios/getHeaders.hbs +++ b/src/templates/core/axios/getHeaders.hbs @@ -26,5 +26,17 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, for headers['Authorization'] = `Basic ${credentials}`; } + if (options.body) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + return headers; }; diff --git a/src/templates/core/axios/request.hbs b/src/templates/core/axios/request.hbs index 439aebe8..8ea274f2 100644 --- a/src/templates/core/axios/request.hbs +++ b/src/templates/core/axios/request.hbs @@ -22,6 +22,9 @@ import type { OpenAPIConfig } from './OpenAPI'; {{>functions/isBlob}} +{{>functions/isFormData}} + + {{>functions/isSuccess}}