swagger-client 3.10.8 → 3.10.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +10 -2
  2. package/dist/swagger-client.browser.js +24191 -0
  3. package/dist/swagger-client.browser.min.js +3 -0
  4. package/dist/swagger-client.browser.min.js.map +1 -0
  5. package/es/commonjs.js +9 -0
  6. package/es/constants.js +2 -0
  7. package/es/execute/index.js +391 -0
  8. package/es/execute/oas3/build-request.js +149 -0
  9. package/es/execute/oas3/content-serializer.js +18 -0
  10. package/es/execute/oas3/parameter-builders.js +119 -0
  11. package/es/execute/oas3/style-serializer.js +232 -0
  12. package/es/execute/swagger2/build-request.js +119 -0
  13. package/es/execute/swagger2/parameter-builders.js +78 -0
  14. package/es/helpers.js +272 -0
  15. package/es/http.js +621 -0
  16. package/es/index.js +116 -0
  17. package/es/interfaces.js +145 -0
  18. package/es/internal/form-data-monkey-patch.js +94 -0
  19. package/es/resolver.js +123 -0
  20. package/es/specmap/helpers.js +62 -0
  21. package/es/specmap/index.js +613 -0
  22. package/es/specmap/lib/all-of.js +81 -0
  23. package/es/specmap/lib/context-tree.js +111 -0
  24. package/es/specmap/lib/create-error.js +24 -0
  25. package/es/specmap/lib/index.js +391 -0
  26. package/es/specmap/lib/parameters.js +31 -0
  27. package/es/specmap/lib/properties.js +23 -0
  28. package/es/specmap/lib/refs.js +516 -0
  29. package/es/subtree-resolver/index.js +92 -0
  30. package/lib/commonjs.js +10 -0
  31. package/lib/constants.js +7 -0
  32. package/lib/execute/index.js +421 -0
  33. package/lib/execute/oas3/build-request.js +161 -0
  34. package/lib/execute/oas3/content-serializer.js +21 -0
  35. package/lib/execute/oas3/parameter-builders.js +138 -0
  36. package/lib/execute/oas3/style-serializer.js +208 -0
  37. package/lib/execute/swagger2/build-request.js +120 -0
  38. package/lib/execute/swagger2/parameter-builders.js +88 -0
  39. package/lib/helpers.js +261 -0
  40. package/lib/http.js +470 -0
  41. package/lib/index.js +142 -0
  42. package/lib/interfaces.js +159 -0
  43. package/lib/internal/form-data-monkey-patch.js +83 -0
  44. package/lib/resolver.js +125 -0
  45. package/lib/specmap/helpers.js +65 -0
  46. package/lib/specmap/index.js +446 -0
  47. package/lib/specmap/lib/all-of.js +89 -0
  48. package/lib/specmap/lib/context-tree.js +111 -0
  49. package/lib/specmap/lib/create-error.js +25 -0
  50. package/lib/specmap/lib/index.js +402 -0
  51. package/lib/specmap/lib/parameters.js +42 -0
  52. package/lib/specmap/lib/properties.js +38 -0
  53. package/lib/specmap/lib/refs.js +509 -0
  54. package/lib/subtree-resolver/index.js +55 -0
  55. package/package.json +80 -106
  56. package/browser/index.js +0 -54
  57. package/dist/index.js +0 -4372
package/lib/http.js ADDED
@@ -0,0 +1,470 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = http;
5
+ exports.serializeRes = serializeRes;
6
+ exports.serializeHeaders = serializeHeaders;
7
+ exports.isFile = isFile;
8
+ exports.encodeFormOrQuery = encodeFormOrQuery;
9
+ exports.mergeInQueryOrForm = mergeInQueryOrForm;
10
+ exports.makeHttp = makeHttp;
11
+ exports.shouldDownloadAsText = exports.self = void 0;
12
+
13
+ require("cross-fetch/polyfill");
14
+
15
+ var _qs = _interopRequireDefault(require("qs"));
16
+
17
+ var _jsYaml = _interopRequireDefault(require("js-yaml"));
18
+
19
+ var _pick = _interopRequireDefault(require("lodash/pick"));
20
+
21
+ var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
22
+
23
+ var _buffer = require("buffer");
24
+
25
+ var _formDataMonkeyPatch = _interopRequireDefault(require("./internal/form-data-monkey-patch"));
26
+
27
+ var _styleSerializer = require("./execute/oas3/style-serializer");
28
+
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+
31
+ /* global fetch */
32
+ // For testing
33
+ const self = {
34
+ serializeRes,
35
+ mergeInQueryOrForm
36
+ }; // Handles fetch-like syntax and the case where there is only one object passed-in
37
+ // (which will have the URL as a property). Also serilizes the response.
38
+
39
+ exports.self = self;
40
+
41
+ async function http(url, request = {}) {
42
+ if (typeof url === 'object') {
43
+ request = url;
44
+ url = request.url;
45
+ }
46
+
47
+ request.headers = request.headers || {}; // Serializes query, for convenience
48
+ // Should be the last thing we do, as its hard to mutate the URL with
49
+ // the search string, but much easier to manipulate the req.query object
50
+
51
+ self.mergeInQueryOrForm(request); // Newlines in header values cause weird error messages from `window.fetch`,
52
+ // so let's massage them out.
53
+ // Context: https://stackoverflow.com/a/50709178
54
+
55
+ if (request.headers) {
56
+ Object.keys(request.headers).forEach(headerName => {
57
+ const value = request.headers[headerName];
58
+
59
+ if (typeof value === 'string') {
60
+ request.headers[headerName] = value.replace(/\n+/g, ' ');
61
+ }
62
+ });
63
+ } // Wait for the request interceptor, if it was provided
64
+ // WARNING: don't put anything between this and the request firing unless
65
+ // you have a good reason!
66
+
67
+
68
+ if (request.requestInterceptor) {
69
+ request = (await request.requestInterceptor(request)) || request;
70
+ } // for content-type=multipart\/form-data remove content-type from request before fetch
71
+ // so that correct one with `boundary` is set
72
+
73
+
74
+ const contentType = request.headers['content-type'] || request.headers['Content-Type'];
75
+
76
+ if (/multipart\/form-data/i.test(contentType)) {
77
+ delete request.headers['content-type'];
78
+ delete request.headers['Content-Type'];
79
+ } // eslint-disable-next-line no-undef
80
+
81
+
82
+ let res;
83
+
84
+ try {
85
+ res = await (request.userFetch || fetch)(request.url, request);
86
+ res = await self.serializeRes(res, url, request);
87
+
88
+ if (request.responseInterceptor) {
89
+ res = (await request.responseInterceptor(res)) || res;
90
+ }
91
+ } catch (resError) {
92
+ if (!res) {
93
+ // res is completely absent, so we can't construct our own error
94
+ // so we'll just throw the error we got
95
+ throw resError;
96
+ }
97
+
98
+ const error = new Error(res.statusText);
99
+ error.status = res.status;
100
+ error.statusCode = res.status;
101
+ error.responseError = resError;
102
+ throw error;
103
+ }
104
+
105
+ if (!res.ok) {
106
+ const error = new Error(res.statusText);
107
+ error.status = res.status;
108
+ error.statusCode = res.status;
109
+ error.response = res;
110
+ throw error;
111
+ }
112
+
113
+ return res;
114
+ } // exported for testing
115
+
116
+
117
+ const shouldDownloadAsText = (contentType = '') => /(json|xml|yaml|text)\b/.test(contentType);
118
+
119
+ exports.shouldDownloadAsText = shouldDownloadAsText;
120
+
121
+ function parseBody(body, contentType) {
122
+ if (contentType && (contentType.indexOf('application/json') === 0 || contentType.indexOf('+json') > 0)) {
123
+ return JSON.parse(body);
124
+ }
125
+
126
+ return _jsYaml.default.safeLoad(body);
127
+ } // Serialize the response, returns a promise with headers and the body part of the hash
128
+
129
+
130
+ function serializeRes(oriRes, url, {
131
+ loadSpec = false
132
+ } = {}) {
133
+ const res = {
134
+ ok: oriRes.ok,
135
+ url: oriRes.url || url,
136
+ status: oriRes.status,
137
+ statusText: oriRes.statusText,
138
+ headers: serializeHeaders(oriRes.headers)
139
+ };
140
+ const contentType = res.headers['content-type'];
141
+ const useText = loadSpec || shouldDownloadAsText(contentType);
142
+ const getBody = useText ? oriRes.text : oriRes.blob || oriRes.buffer;
143
+ return getBody.call(oriRes).then(body => {
144
+ res.text = body;
145
+ res.data = body;
146
+
147
+ if (useText) {
148
+ try {
149
+ const obj = parseBody(body, contentType);
150
+ res.body = obj;
151
+ res.obj = obj;
152
+ } catch (e) {
153
+ res.parseError = e;
154
+ }
155
+ }
156
+
157
+ return res;
158
+ });
159
+ }
160
+
161
+ function serializeHeaderValue(value) {
162
+ const isMulti = value.includes(', ');
163
+ return isMulti ? value.split(', ') : value;
164
+ } // Serialize headers into a hash, where mutliple-headers result in an array.
165
+ //
166
+ // eg: Cookie: one
167
+ // Cookie: two
168
+ // = { Cookie: [ "one", "two" ]
169
+
170
+
171
+ function serializeHeaders(headers = {}) {
172
+ if (!(0, _isFunction.default)(headers.entries)) return {};
173
+ return Array.from(headers.entries()).reduce((acc, [header, value]) => {
174
+ acc[header] = serializeHeaderValue(value);
175
+ return acc;
176
+ }, {});
177
+ }
178
+
179
+ function isFile(obj, navigatorObj) {
180
+ if (!navigatorObj && typeof navigator !== 'undefined') {
181
+ // eslint-disable-next-line no-undef
182
+ navigatorObj = navigator;
183
+ }
184
+
185
+ if (navigatorObj && navigatorObj.product === 'ReactNative') {
186
+ if (obj && typeof obj === 'object' && typeof obj.uri === 'string') {
187
+ return true;
188
+ }
189
+
190
+ return false;
191
+ }
192
+
193
+ if (typeof File !== 'undefined' && obj instanceof File) {
194
+ // eslint-disable-line no-undef
195
+ return true;
196
+ }
197
+
198
+ if (typeof Blob !== 'undefined' && obj instanceof Blob) {
199
+ // eslint-disable-line no-undef
200
+ return true;
201
+ }
202
+
203
+ if (typeof _buffer.Buffer !== 'undefined' && obj instanceof _buffer.Buffer) {
204
+ return true;
205
+ }
206
+
207
+ return obj !== null && typeof obj === 'object' && typeof obj.pipe === 'function';
208
+ }
209
+
210
+ function isArrayOfFile(obj, navigatorObj) {
211
+ return Array.isArray(obj) && obj.some(v => isFile(v, navigatorObj));
212
+ }
213
+
214
+ const STYLE_SEPARATORS = {
215
+ form: ',',
216
+ spaceDelimited: '%20',
217
+ pipeDelimited: '|'
218
+ };
219
+ const SEPARATORS = {
220
+ csv: ',',
221
+ ssv: '%20',
222
+ tsv: '%09',
223
+ pipes: '|'
224
+ }; // Formats a key-value and returns an array of key-value pairs.
225
+ //
226
+ // Return value example 1: [['color', 'blue']]
227
+ // Return value example 2: [['color', 'blue,black,brown']]
228
+ // Return value example 3: [['color', ['blue', 'black', 'brown']]]
229
+ // Return value example 4: [['color', 'R,100,G,200,B,150']]
230
+ // Return value example 5: [['R', '100'], ['G', '200'], ['B', '150']]
231
+ // Return value example 6: [['color[R]', '100'], ['color[G]', '200'], ['color[B]', '150']]
232
+
233
+ function formatKeyValue(key, input, skipEncoding = false) {
234
+ const {
235
+ collectionFormat,
236
+ allowEmptyValue,
237
+ serializationOption,
238
+ encoding
239
+ } = input; // `input` can be string
240
+
241
+ const value = typeof input === 'object' && !Array.isArray(input) ? input.value : input;
242
+ const encodeFn = skipEncoding ? k => k.toString() : k => encodeURIComponent(k);
243
+ const encodedKey = encodeFn(key);
244
+
245
+ if (typeof value === 'undefined' && allowEmptyValue) {
246
+ return [[encodedKey, '']];
247
+ } // file
248
+
249
+
250
+ if (isFile(value) || isArrayOfFile(value)) {
251
+ return [[encodedKey, value]];
252
+ } // for OAS 3 Parameter Object for serialization
253
+
254
+
255
+ if (serializationOption) {
256
+ return formatKeyValueBySerializationOption(key, value, skipEncoding, serializationOption);
257
+ } // for OAS 3 Encoding Object
258
+
259
+
260
+ if (encoding) {
261
+ if ([typeof encoding.style, typeof encoding.explode, typeof encoding.allowReserved].some(type => type !== 'undefined')) {
262
+ return formatKeyValueBySerializationOption(key, value, skipEncoding, (0, _pick.default)(encoding, ['style', 'explode', 'allowReserved']));
263
+ }
264
+
265
+ if (encoding.contentType) {
266
+ if (encoding.contentType === 'application/json') {
267
+ // If value is a string, assume value is already a JSON string
268
+ const json = typeof value === 'string' ? value : JSON.stringify(value);
269
+ return [[encodedKey, encodeFn(json)]];
270
+ }
271
+
272
+ return [[encodedKey, encodeFn(value.toString())]];
273
+ } // Primitive
274
+
275
+
276
+ if (typeof value !== 'object') {
277
+ return [[encodedKey, encodeFn(value)]];
278
+ } // Array of primitives
279
+
280
+
281
+ if (Array.isArray(value) && value.every(v => typeof v !== 'object')) {
282
+ return [[encodedKey, value.map(encodeFn).join(',')]];
283
+ } // Array or object
284
+
285
+
286
+ return [[encodedKey, encodeFn(JSON.stringify(value))]];
287
+ } // for OAS 2 Parameter Object
288
+ // Primitive
289
+
290
+
291
+ if (typeof value !== 'object') {
292
+ return [[encodedKey, encodeFn(value)]];
293
+ } // Array
294
+
295
+
296
+ if (Array.isArray(value)) {
297
+ if (collectionFormat === 'multi') {
298
+ // In case of multipart/formdata, it is used as array.
299
+ // Otherwise, the caller will convert it to a query by qs.stringify.
300
+ return [[encodedKey, value.map(encodeFn)]];
301
+ }
302
+
303
+ return [[encodedKey, value.map(encodeFn).join(SEPARATORS[collectionFormat || 'csv'])]];
304
+ } // Object
305
+
306
+
307
+ return [[encodedKey, '']];
308
+ }
309
+
310
+ function formatKeyValueBySerializationOption(key, value, skipEncoding, serializationOption) {
311
+ const style = serializationOption.style || 'form';
312
+ const explode = typeof serializationOption.explode === 'undefined' ? style === 'form' : serializationOption.explode; // eslint-disable-next-line no-nested-ternary
313
+
314
+ const escape = skipEncoding ? false : serializationOption && serializationOption.allowReserved ? 'unsafe' : 'reserved';
315
+
316
+ const encodeFn = v => (0, _styleSerializer.encodeDisallowedCharacters)(v, {
317
+ escape
318
+ });
319
+
320
+ const encodeKeyFn = skipEncoding ? k => k : k => (0, _styleSerializer.encodeDisallowedCharacters)(k, {
321
+ escape
322
+ }); // Primitive
323
+
324
+ if (typeof value !== 'object') {
325
+ return [[encodeKeyFn(key), encodeFn(value)]];
326
+ } // Array
327
+
328
+
329
+ if (Array.isArray(value)) {
330
+ if (explode) {
331
+ // In case of multipart/formdata, it is used as array.
332
+ // Otherwise, the caller will convert it to a query by qs.stringify.
333
+ return [[encodeKeyFn(key), value.map(encodeFn)]];
334
+ }
335
+
336
+ return [[encodeKeyFn(key), value.map(encodeFn).join(STYLE_SEPARATORS[style])]];
337
+ } // Object
338
+
339
+
340
+ if (style === 'deepObject') {
341
+ return Object.keys(value).map(valueKey => [encodeKeyFn(`${key}[${valueKey}]`), encodeFn(value[valueKey])]);
342
+ }
343
+
344
+ if (explode) {
345
+ return Object.keys(value).map(valueKey => [encodeKeyFn(valueKey), encodeFn(value[valueKey])]);
346
+ }
347
+
348
+ return [[encodeKeyFn(key), Object.keys(value).map(valueKey => [`${encodeKeyFn(valueKey)},${encodeFn(value[valueKey])}`]).join(',')]];
349
+ }
350
+
351
+ function buildFormData(reqForm) {
352
+ /**
353
+ * Build a new FormData instance, support array as field value
354
+ * OAS2.0 - when collectionFormat is multi
355
+ * OAS3.0 - when explode of Encoding Object is true
356
+ * @param {Object} reqForm - ori req.form
357
+ * @return {FormData} - new FormData instance
358
+ */
359
+ return Object.entries(reqForm).reduce((formData, [name, input]) => {
360
+ // eslint-disable-next-line no-restricted-syntax
361
+ for (const [key, value] of formatKeyValue(name, input, true)) {
362
+ if (Array.isArray(value)) {
363
+ // eslint-disable-next-line no-restricted-syntax
364
+ for (const v of value) {
365
+ formData.append(key, v);
366
+ }
367
+ } else {
368
+ formData.append(key, value);
369
+ }
370
+ }
371
+
372
+ return formData;
373
+ }, new _formDataMonkeyPatch.default());
374
+ } // Encodes an object using appropriate serializer.
375
+
376
+
377
+ function encodeFormOrQuery(data) {
378
+ /**
379
+ * Encode parameter names and values
380
+ * @param {Object} result - parameter names and values
381
+ * @param {string} parameterName - Parameter name
382
+ * @return {object} encoded parameter names and values
383
+ */
384
+ const encodedQuery = Object.keys(data).reduce((result, parameterName) => {
385
+ // eslint-disable-next-line no-restricted-syntax
386
+ for (const [key, value] of formatKeyValue(parameterName, data[parameterName])) {
387
+ result[key] = value;
388
+ }
389
+
390
+ return result;
391
+ }, {});
392
+ return _qs.default.stringify(encodedQuery, {
393
+ encode: false,
394
+ indices: false
395
+ }) || '';
396
+ } // If the request has a `query` object, merge it into the request.url, and delete the object
397
+ // If file and/or multipart, also create FormData instance
398
+
399
+
400
+ function mergeInQueryOrForm(req = {}) {
401
+ const {
402
+ url = '',
403
+ query,
404
+ form
405
+ } = req;
406
+
407
+ const joinSearch = (...strs) => {
408
+ const search = strs.filter(a => a).join('&'); // Only truthy value
409
+
410
+ return search ? `?${search}` : ''; // Only add '?' if there is a str
411
+ };
412
+
413
+ if (form) {
414
+ const hasFile = Object.keys(form).some(key => {
415
+ const {
416
+ value
417
+ } = form[key];
418
+ return isFile(value) || isArrayOfFile(value);
419
+ });
420
+ const contentType = req.headers['content-type'] || req.headers['Content-Type'];
421
+
422
+ if (hasFile || /multipart\/form-data/i.test(contentType)) {
423
+ req.body = buildFormData(req.form);
424
+ } else {
425
+ req.body = encodeFormOrQuery(form);
426
+ }
427
+
428
+ delete req.form;
429
+ }
430
+
431
+ if (query) {
432
+ const [baseUrl, oriSearch] = url.split('?');
433
+ let newStr = '';
434
+
435
+ if (oriSearch) {
436
+ const oriQuery = _qs.default.parse(oriSearch);
437
+
438
+ const keysToRemove = Object.keys(query);
439
+ keysToRemove.forEach(key => delete oriQuery[key]);
440
+ newStr = _qs.default.stringify(oriQuery, {
441
+ encode: true
442
+ });
443
+ }
444
+
445
+ const finalStr = joinSearch(newStr, encodeFormOrQuery(query));
446
+ req.url = baseUrl + finalStr;
447
+ delete req.query;
448
+ }
449
+
450
+ return req;
451
+ } // Wrap a http function ( there are otherways to do this, consider this deprecated )
452
+
453
+
454
+ function makeHttp(httpFn, preFetch, postFetch) {
455
+ postFetch = postFetch || (a => a);
456
+
457
+ preFetch = preFetch || (a => a);
458
+
459
+ return req => {
460
+ if (typeof req === 'string') {
461
+ req = {
462
+ url: req
463
+ };
464
+ }
465
+
466
+ self.mergeInQueryOrForm(req);
467
+ req = preFetch(req);
468
+ return postFetch(httpFn(req));
469
+ };
470
+ }
package/lib/index.js ADDED
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = exports.helpers = void 0;
5
+
6
+ var _assign = _interopRequireDefault(require("lodash/assign"));
7
+
8
+ var _startsWith = _interopRequireDefault(require("lodash/startsWith"));
9
+
10
+ var _url = _interopRequireDefault(require("url"));
11
+
12
+ var _http = _interopRequireWildcard(require("./http"));
13
+
14
+ var _resolver = _interopRequireWildcard(require("./resolver"));
15
+
16
+ var _subtreeResolver = _interopRequireDefault(require("./subtree-resolver"));
17
+
18
+ var _interfaces = require("./interfaces");
19
+
20
+ var _execute = require("./execute");
21
+
22
+ var _helpers = require("./helpers");
23
+
24
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
25
+
26
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ Swagger.http = _http.default;
37
+ Swagger.makeHttp = _http.makeHttp.bind(null, Swagger.http);
38
+ Swagger.resolve = _resolver.default;
39
+ Swagger.resolveSubtree = _subtreeResolver.default;
40
+ Swagger.execute = _execute.execute;
41
+ Swagger.serializeRes = _http.serializeRes;
42
+ Swagger.serializeHeaders = _http.serializeHeaders;
43
+ Swagger.clearCache = _resolver.clearCache;
44
+ Swagger.makeApisTagOperation = _interfaces.makeApisTagOperation;
45
+ Swagger.buildRequest = _execute.buildRequest;
46
+ Swagger.helpers = {
47
+ opId: _helpers.opId
48
+ };
49
+ Swagger.getBaseUrl = _execute.baseUrl;
50
+
51
+ function Swagger(url, opts = {}) {
52
+ // Allow url as a separate argument
53
+ if (typeof url === 'string') {
54
+ opts.url = url;
55
+ } else {
56
+ opts = url;
57
+ }
58
+
59
+ if (!(this instanceof Swagger)) {
60
+ return new Swagger(opts);
61
+ }
62
+
63
+ (0, _assign.default)(this, opts);
64
+ const prom = this.resolve().then(() => {
65
+ if (!this.disableInterfaces) {
66
+ (0, _assign.default)(this, Swagger.makeApisTagOperation(this));
67
+ }
68
+
69
+ return this;
70
+ }); // Expose this instance on the promise that gets returned
71
+
72
+ prom.client = this;
73
+ return prom;
74
+ }
75
+
76
+ Swagger.prototype = {
77
+ http: _http.default,
78
+
79
+ execute(options) {
80
+ this.applyDefaults();
81
+ return Swagger.execute(_objectSpread({
82
+ spec: this.spec,
83
+ http: this.http,
84
+ securities: {
85
+ authorized: this.authorizations
86
+ },
87
+ contextUrl: typeof this.url === 'string' ? this.url : undefined,
88
+ requestInterceptor: this.requestInterceptor || null,
89
+ responseInterceptor: this.responseInterceptor || null
90
+ }, options));
91
+ },
92
+
93
+ resolve(options = {}) {
94
+ return Swagger.resolve(_objectSpread({
95
+ spec: this.spec,
96
+ url: this.url,
97
+ http: this.http || this.fetch,
98
+ allowMetaPatches: this.allowMetaPatches,
99
+ useCircularStructures: this.useCircularStructures,
100
+ requestInterceptor: this.requestInterceptor || null,
101
+ responseInterceptor: this.responseInterceptor || null
102
+ }, options)).then(obj => {
103
+ this.originalSpec = this.spec;
104
+ this.spec = obj.spec;
105
+ this.errors = obj.errors;
106
+ return this;
107
+ });
108
+ }
109
+
110
+ };
111
+
112
+ Swagger.prototype.applyDefaults = function applyDefaults() {
113
+ const {
114
+ spec
115
+ } = this;
116
+ const specUrl = this.url; // TODO: OAS3: support servers here
117
+
118
+ if (specUrl && (0, _startsWith.default)(specUrl, 'http')) {
119
+ const parsed = _url.default.parse(specUrl);
120
+
121
+ if (!spec.host) {
122
+ spec.host = parsed.host;
123
+ }
124
+
125
+ if (!spec.schemes) {
126
+ spec.schemes = [parsed.protocol.replace(':', '')];
127
+ }
128
+
129
+ if (!spec.basePath) {
130
+ spec.basePath = '/';
131
+ }
132
+ }
133
+ }; // add backwards compatibility with older versions of swagger-ui
134
+ // Refs https://github.com/swagger-api/swagger-ui/issues/6210
135
+
136
+
137
+ const {
138
+ helpers
139
+ } = Swagger;
140
+ exports.helpers = helpers;
141
+ var _default = Swagger;
142
+ exports.default = _default;