1 | import _regeneratorRuntime from "@babel/runtime-corejs2/regenerator";
|
2 | import _asyncToGenerator from "@babel/runtime-corejs2/helpers/asyncToGenerator";
|
3 | import Http from './http';
|
4 | import mapSpec, { plugins } from './specmap';
|
5 | import { normalizeSwagger } from './helpers';
|
6 | import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from './constants';
|
7 | export function makeFetchJSON(http) {
|
8 | var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
9 | var requestInterceptor = opts.requestInterceptor,
|
10 | responseInterceptor = opts.responseInterceptor;
|
11 |
|
12 | var credentials = http.withCredentials ? 'include' : 'same-origin';
|
13 | return function (docPath) {
|
14 | return http({
|
15 | url: docPath,
|
16 | loadSpec: true,
|
17 | requestInterceptor: requestInterceptor,
|
18 | responseInterceptor: responseInterceptor,
|
19 | headers: {
|
20 | Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS
|
21 | },
|
22 | credentials: credentials
|
23 | }).then(function (res) {
|
24 | return res.body;
|
25 | });
|
26 | };
|
27 | }
|
28 |
|
29 | export function clearCache() {
|
30 | plugins.refs.clearCache();
|
31 | }
|
32 | export default function resolve(obj) {
|
33 | var fetch = obj.fetch,
|
34 | spec = obj.spec,
|
35 | url = obj.url,
|
36 | mode = obj.mode,
|
37 | _obj$allowMetaPatches = obj.allowMetaPatches,
|
38 | allowMetaPatches = _obj$allowMetaPatches === void 0 ? true : _obj$allowMetaPatches,
|
39 | pathDiscriminator = obj.pathDiscriminator,
|
40 | modelPropertyMacro = obj.modelPropertyMacro,
|
41 | parameterMacro = obj.parameterMacro,
|
42 | requestInterceptor = obj.requestInterceptor,
|
43 | responseInterceptor = obj.responseInterceptor,
|
44 | skipNormalization = obj.skipNormalization,
|
45 | useCircularStructures = obj.useCircularStructures;
|
46 | var http = obj.http,
|
47 | baseDoc = obj.baseDoc;
|
48 |
|
49 |
|
50 | baseDoc = baseDoc || url;
|
51 |
|
52 |
|
53 | http = fetch || http || Http;
|
54 |
|
55 | if (!spec) {
|
56 | return makeFetchJSON(http, {
|
57 | requestInterceptor: requestInterceptor,
|
58 | responseInterceptor: responseInterceptor
|
59 | })(baseDoc).then(doResolve);
|
60 | }
|
61 |
|
62 | return doResolve(spec);
|
63 |
|
64 | function doResolve(_spec) {
|
65 | if (baseDoc) {
|
66 | plugins.refs.docCache[baseDoc] = _spec;
|
67 | }
|
68 |
|
69 |
|
70 | plugins.refs.fetchJSON = makeFetchJSON(http, {
|
71 | requestInterceptor: requestInterceptor,
|
72 | responseInterceptor: responseInterceptor
|
73 | });
|
74 | var plugs = [plugins.refs];
|
75 |
|
76 | if (typeof parameterMacro === 'function') {
|
77 | plugs.push(plugins.parameters);
|
78 | }
|
79 |
|
80 | if (typeof modelPropertyMacro === 'function') {
|
81 | plugs.push(plugins.properties);
|
82 | }
|
83 |
|
84 | if (mode !== 'strict') {
|
85 | plugs.push(plugins.allOf);
|
86 | }
|
87 |
|
88 |
|
89 | return mapSpec({
|
90 | spec: _spec,
|
91 | context: {
|
92 | baseDoc: baseDoc
|
93 | },
|
94 | plugins: plugs,
|
95 | allowMetaPatches: allowMetaPatches,
|
96 |
|
97 | pathDiscriminator: pathDiscriminator,
|
98 |
|
99 | parameterMacro: parameterMacro,
|
100 | modelPropertyMacro: modelPropertyMacro,
|
101 | useCircularStructures: useCircularStructures
|
102 | }).then(skipNormalization ? function () {
|
103 | var _ref = _asyncToGenerator( _regeneratorRuntime.mark(function _callee(a) {
|
104 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
105 | while (1) {
|
106 | switch (_context.prev = _context.next) {
|
107 | case 0:
|
108 | return _context.abrupt("return", a);
|
109 |
|
110 | case 1:
|
111 | case "end":
|
112 | return _context.stop();
|
113 | }
|
114 | }
|
115 | }, _callee);
|
116 | }));
|
117 |
|
118 | return function (_x) {
|
119 | return _ref.apply(this, arguments);
|
120 | };
|
121 | }() : normalizeSwagger);
|
122 | }
|
123 | } |
\ | No newline at end of file |