Skip to content

Commit

Permalink
fix: axios适配器不兼容foca-axios
Browse files Browse the repository at this point in the history
  • Loading branch information
geekact committed Oct 7, 2024
1 parent 5fc3343 commit 31642aa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"@types/node": "^20.14.10",
"@types/qs": "^6.9.15",
"@vitest/coverage-v8": "^2.0.3",
"axios": "^1.7.2",
"axios": "^1.7.7",
"foca-axios": "^4.1.1",
"husky": "^9.0.11",
"only-allow": "^1.2.1",
"release-it": "^17.6.0",
Expand Down
29 changes: 24 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/adapters/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios';
*
*/
export const axiosAdapter = (
axios: { request: (config: AxiosRequestConfig) => Promise<AxiosResponse> },
axios: { request: (config: object) => Promise<AxiosResponse> },
returningData: (response: AxiosResponse) => any = (response) => response.data,
): OpenapiClientAdapter<AxiosRequestConfig> => {
return {
Expand Down
17 changes: 17 additions & 0 deletions test/adapters/axios.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import axios, { Axios } from 'axios';
import { axiosAdapter } from '../../src/adapters/axios';
import * as focaAxios from 'foca-axios';

// 原生axios
{
axiosAdapter(axios);
axiosAdapter(axios.create());
axiosAdapter(new Axios({}));
}

// foca-axios
{
axiosAdapter(focaAxios.axios);
axiosAdapter(focaAxios.default);
axiosAdapter(focaAxios.axios.create());
}

0 comments on commit 31642aa

Please sign in to comment.