Skip to content

Commit 4b4ccfa

Browse files
committed
feat: add a way to provide an axios instance
Signed-off-by: Jeremie Drouet <[email protected]>
1 parent 7435b0d commit 4b4ccfa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/axios/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const AXIOS_DEPENDENCIES: GeneratorDependency[] = [
2828
values: true,
2929
syntheticDefaultImport: true,
3030
},
31+
{ name: 'AxiosInstance' },
3132
{ name: 'AxiosRequestConfig' },
3233
{ name: 'AxiosResponse' },
3334
],
@@ -176,7 +177,7 @@ const generateAxiosImplementation = (
176177
}>>(\n ${toObjectString(props, 'implementation')} ${
177178
isRequestOptions ? `options?: AxiosRequestConfig\n` : ''
178179
} ): Promise<TData> => {${bodyForm}
179-
return axios${
180+
return axiosInstance${
180181
isSyntheticDefaultImportsAllowed ? '' : '.default'
181182
}.${verb}(${options});
182183
}
@@ -199,7 +200,7 @@ ${
199200
? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n`
200201
: ''
201202
}
202-
${noFunction ? '' : `export const ${title} = () => {\n`}`;
203+
${noFunction ? '' : `export const ${title} = (axiosInstance: AxiosInstance = axios.create()) => {\n`}`;
203204

204205
export const generateAxiosFooter: ClientFooterBuilder = ({
205206
operationNames,

0 commit comments

Comments
 (0)