main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import { makeFetchJSON } from './utils/index.js';
|
---|
| 2 | import * as optionsUtil from './utils/options.js';
|
---|
| 3 | import genericStrategy from './strategies/generic/index.js';
|
---|
| 4 | import openApi2Strategy from './strategies/openapi-2/index.js';
|
---|
| 5 | import openApi30Strategy from './strategies/openapi-3-0/index.js';
|
---|
| 6 | const resolve = async options => {
|
---|
| 7 | const {
|
---|
| 8 | spec,
|
---|
| 9 | requestInterceptor,
|
---|
| 10 | responseInterceptor
|
---|
| 11 | } = options;
|
---|
| 12 | const retrievalURI = optionsUtil.retrievalURI(options);
|
---|
| 13 | const httpClient = optionsUtil.httpClient(options);
|
---|
| 14 | const retrievedSpec = spec || (await makeFetchJSON(httpClient, {
|
---|
| 15 | requestInterceptor,
|
---|
| 16 | responseInterceptor
|
---|
| 17 | })(retrievalURI));
|
---|
| 18 | const strategyOptions = {
|
---|
| 19 | ...options,
|
---|
| 20 | spec: retrievedSpec
|
---|
| 21 | };
|
---|
| 22 | const strategy = options.strategies.find(strg => strg.match(strategyOptions));
|
---|
| 23 | return strategy.resolve(strategyOptions);
|
---|
| 24 | };
|
---|
| 25 | export const makeResolve = defaultOptions => async options => {
|
---|
| 26 | const mergedOptions = {
|
---|
| 27 | ...defaultOptions,
|
---|
| 28 | ...options
|
---|
| 29 | };
|
---|
| 30 | return resolve(mergedOptions);
|
---|
| 31 | };
|
---|
| 32 | export default makeResolve({
|
---|
| 33 | strategies: [openApi30Strategy, openApi2Strategy, genericStrategy]
|
---|
| 34 | }); |
---|
Note:
See
TracBrowser
for help on using the repository browser.