Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/apidom-reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ await resolve('/home/user/oas.json', {
}); // Promise<ReferenceSet>
```

**Externally resolving a HTTP(S) URL located on an internet:**
**Externally resolving an HTTP(S) URL located on an internet:**

```js
import { resolve } from '@swagger-api/apidom-reference';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import stampit from 'stampit';
import { omit, pathOr } from 'ramda';
import { ensureArray } from 'ramda-adjunct';
import axios, { AxiosInstance } from 'axios';

import ResolverError from '../../util/errors/ResolverError';
Expand All @@ -21,13 +23,35 @@ const HttpResolverAxios: stampit.Stamp<IHttpResolver> = stampit(HttpResolver).in

this.getHttpClient = function getHttpClient(): AxiosInstance {
if (typeof axiosInstance === 'undefined' || oldAxiosConfig !== this.axiosConfig) {
const config = omit(['interceptors'], this.axiosConfig);
const interceptors = pathOr(
{ request: [], response: [] },
['axiosConfig', 'interceptors'],
this,
);

axiosInstance = axios.create({
timeout: this.timeout,
maxRedirects: this.redirects,
withCredentials: this.withCredentials,
responseType: 'arraybuffer',
...(this.axiosConfig || {}),
...config,
});

// settings up request interceptors
if (Array.isArray(interceptors?.request)) {
interceptors.request.forEach((requestInterceptor: any) => {
axiosInstance.interceptors.request.use(...ensureArray(requestInterceptor));
});
}

// settings up response interceptors
if (Array.isArray(interceptors?.response)) {
interceptors.response.forEach((responseInterceptor: any) => {
axiosInstance.interceptors.response.use(...ensureArray(responseInterceptor));
});
}

oldAxiosConfig = this.axiosConfig;
}

Expand Down