-
Notifications
You must be signed in to change notification settings - Fork 760
/
Copy pathindex.js
28 lines (23 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { makeFetchJSON } from './utils/index.js';
import * as optionsUtil from './utils/options.js';
import genericStrategy from './strategies/generic/index.js';
import openApi2Strategy from './strategies/openapi-2/index.js';
import openApi30Strategy from './strategies/openapi-3-0/index.js';
const resolve = async (options) => {
const { spec, requestInterceptor, responseInterceptor } = options;
const retrievalURI = optionsUtil.retrievalURI(options);
const httpClient = optionsUtil.httpClient(options);
const retrievedSpec =
spec ||
(await makeFetchJSON(httpClient, { requestInterceptor, responseInterceptor })(retrievalURI));
const strategyOptions = { ...options, spec: retrievedSpec };
const strategy = options.strategies.find((strg) => strg.match(retrievedSpec));
return strategy.resolve(strategyOptions);
};
export const makeResolve = (defaultOptions) => async (options) => {
const mergedOptions = { ...defaultOptions, ...options };
return resolve(mergedOptions);
};
export default makeResolve({
strategies: [openApi30Strategy, openApi2Strategy, genericStrategy],
});