From 3ed205a6015ca74c2c045ba8613cd25a923319d4 Mon Sep 17 00:00:00 2001 From: Cameron Koegel <53310569+ckoegel@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:49:10 -0500 Subject: [PATCH] SWI-3723 Fix Axios Typing with 1.6.0 (#63) * SWI-3723 Fix Axios Typing with 1.6.0 * update package json to fix import issue --- package.json | 5 +++++ src/http/httpClient.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bf8e7b0..1846373 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,11 @@ "lodash.flatmap": "^4.5.0", "tiny-warning": "^1.0.3" }, + "jest": { + "moduleNameMapper": { + "axios": "axios/dist/node/axios.cjs" + } + }, "bugs": { "email": "support@bandwidth.com" } diff --git a/src/http/httpClient.ts b/src/http/httpClient.ts index 37bc6d6..6fcae81 100644 --- a/src/http/httpClient.ts +++ b/src/http/httpClient.ts @@ -4,7 +4,7 @@ * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). */ - import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; + import axios, { AxiosHeaders, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; import isNode from 'detect-node'; import FormData from 'form-data'; import { isBlob } from '../apiHelper'; @@ -91,14 +91,14 @@ } newRequest.data = form; - mergeHeaders(newRequest.headers || {} , form.getHeaders()); + mergeHeaders(newRequest.headers as AxiosHeaders || {} , form.getHeaders()); } else if ( requestBody?.type === 'form-data' || requestBody?.type === 'form' ) { // Create form-urlencoded request setHeader( - newRequest.headers || {}, + newRequest.headers as AxiosHeaders || {}, CONTENT_TYPE_HEADER, FORM_URLENCODED_CONTENT_TYPE ); @@ -112,7 +112,7 @@ // Otherwise, use the content type if available. contentType = requestBody.content.options.contentType; } - setHeaderIfNotSet(newRequest.headers || {}, CONTENT_TYPE_HEADER, contentType); + setHeaderIfNotSet(newRequest.headers as AxiosHeaders || {}, CONTENT_TYPE_HEADER, contentType); newRequest.data = requestBody.content.file; } else if (requestBody && typeof(requestBody['type']) !== 'undefined') { @@ -139,7 +139,7 @@ public convertHttpResponse(resp: AxiosResponse): HttpResponse { return { body: resp.data, - headers: resp.headers, + headers: resp.headers as AxiosHeaders, statusCode: resp.status, }; } @@ -185,4 +185,4 @@ return new AbortError('The HTTP call was aborted.'); } } - \ No newline at end of file +