swagger-client 3.20.1 → 3.21.0

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 (91) hide show
  1. package/README.md +19 -2
  2. package/dist/swagger-client.browser.js +13796 -16135
  3. package/dist/swagger-client.browser.min.js +1 -1
  4. package/dist/swagger-client.browser.min.js.map +1 -1
  5. package/es/execute/index.js +53 -27
  6. package/es/execute/oas3/build-request.js +7 -5
  7. package/es/execute/swagger2/build-request.js +3 -2
  8. package/es/helpers/fetch-polyfill.browser.js +13 -0
  9. package/es/helpers/fetch-polyfill.node.js +14 -0
  10. package/es/helpers/fetch-ponyfill-node-fetch.node.js +3 -0
  11. package/es/helpers/fetch-ponyfill-undici.node.js +2 -0
  12. package/es/helpers/fetch-ponyfill.browser.js +8 -0
  13. package/es/http/index.js +10 -9
  14. package/es/index.js +9 -9
  15. package/es/interfaces.js +4 -4
  16. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +2 -1
  17. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +4 -2
  18. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +26 -18
  19. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +2 -1
  20. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +2 -1
  21. package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +12 -10
  22. package/es/resolver/index.js +7 -4
  23. package/es/resolver/strategies/openapi-3-1-apidom/normalize.js +1 -1
  24. package/es/specmap/helpers.js +2 -2
  25. package/es/specmap/index.js +6 -4
  26. package/es/specmap/lib/all-of.js +3 -2
  27. package/es/specmap/lib/context-tree.js +4 -2
  28. package/es/specmap/lib/index.js +11 -5
  29. package/es/specmap/lib/parameters.js +3 -2
  30. package/es/specmap/lib/properties.js +3 -2
  31. package/es/specmap/lib/refs.js +2 -2
  32. package/es/subtree-resolver/index.js +8 -6
  33. package/lib/execute/index.js +77 -49
  34. package/lib/execute/oas3/build-request.js +22 -18
  35. package/lib/execute/oas3/parameter-builders.js +26 -23
  36. package/lib/execute/oas3/style-serializer.js +27 -23
  37. package/lib/execute/swagger2/build-request.js +11 -13
  38. package/lib/execute/swagger2/parameter-builders.js +29 -24
  39. package/lib/helpers/fetch-polyfill.browser.js +15 -0
  40. package/lib/helpers/fetch-polyfill.node.js +16 -0
  41. package/lib/helpers/fetch-ponyfill-node-fetch.node.js +9 -0
  42. package/lib/helpers/fetch-ponyfill-undici.node.js +8 -0
  43. package/lib/helpers/fetch-ponyfill.browser.js +15 -0
  44. package/lib/helpers/find-operation.js +1 -1
  45. package/lib/helpers/get-operation-raw.js +7 -6
  46. package/lib/helpers/id-from-path-method/index.js +5 -4
  47. package/lib/helpers/index.js +2 -2
  48. package/lib/helpers/op-id.js +8 -4
  49. package/lib/http/index.js +52 -22
  50. package/lib/index.js +21 -18
  51. package/lib/interfaces.js +49 -36
  52. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +1 -1
  53. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +12 -12
  54. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +1 -1
  55. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +9 -8
  56. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +29 -28
  57. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +8 -7
  58. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +8 -7
  59. package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +1 -2
  60. package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +1 -2
  61. package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +18 -19
  62. package/lib/resolver/index.js +9 -11
  63. package/lib/resolver/strategies/generic/index.js +5 -4
  64. package/lib/resolver/strategies/generic/normalize.js +1 -1
  65. package/lib/resolver/strategies/generic/resolve.js +2 -3
  66. package/lib/resolver/strategies/openapi-2/index.js +9 -7
  67. package/lib/resolver/strategies/openapi-2/normalize.js +2 -2
  68. package/lib/resolver/strategies/openapi-2/resolve.js +1 -1
  69. package/lib/resolver/strategies/openapi-3-0/index.js +9 -7
  70. package/lib/resolver/strategies/openapi-3-0/normalize.js +2 -2
  71. package/lib/resolver/strategies/openapi-3-0/resolve.js +1 -1
  72. package/lib/resolver/strategies/openapi-3-1-apidom/index.js +10 -9
  73. package/lib/resolver/strategies/openapi-3-1-apidom/normalize.js +2 -2
  74. package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +2 -3
  75. package/lib/resolver/utils/index.js +4 -1
  76. package/lib/resolver/utils/options.js +1 -1
  77. package/lib/specmap/helpers.js +9 -8
  78. package/lib/specmap/index.js +15 -11
  79. package/lib/specmap/lib/all-of.js +3 -6
  80. package/lib/specmap/lib/context-tree.js +4 -6
  81. package/lib/specmap/lib/create-error.js +4 -1
  82. package/lib/specmap/lib/index.js +13 -12
  83. package/lib/specmap/lib/parameters.js +4 -7
  84. package/lib/specmap/lib/properties.js +4 -7
  85. package/lib/specmap/lib/refs.js +4 -4
  86. package/lib/subtree-resolver/index.js +19 -13
  87. package/package.json +17 -26
  88. package/es/http/fold-formdata-to-request.browser.js +0 -4
  89. package/es/http/fold-formdata-to-request.node.js +0 -29
  90. package/lib/http/fold-formdata-to-request.browser.js +0 -9
  91. package/lib/http/fold-formdata-to-request.node.js +0 -37
@@ -1,10 +1,6 @@
1
- import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties";
3
- const _excluded = ["http", "fetch", "spec", "operationId", "pathName", "method", "parameters", "securities"];
4
- import getIn from 'lodash/get';
5
- import url from 'url';
6
1
  import cookie from 'cookie';
7
2
  import { isPlainObject } from 'is-plain-object';
3
+ import { url } from '@swagger-api/apidom-reference/configuration/empty';
8
4
  import stockHttp, { mergeInQueryOrForm } from '../http/index.js';
9
5
  import createError from '../specmap/lib/create-error.js';
10
6
  import SWAGGER2_PARAMETER_BUILDERS from './swagger2/parameter-builders.js';
@@ -14,6 +10,33 @@ import swagger2BuildRequest from './swagger2/build-request.js';
14
10
  import { getOperationRaw, idFromPathMethodLegacy } from '../helpers/index.js';
15
11
  import { isOpenAPI3 } from '../helpers/openapi-predicates.js';
16
12
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
13
+
14
+ /**
15
+ * `parseURIReference` function simulates the behavior of `node:url` parse function.
16
+ * New WHATWG URL API is not capable of parsing relative references natively,
17
+ * but can be adapter by utilizing the `base` parameter.
18
+ */
19
+ const parseURIReference = uriReference => {
20
+ try {
21
+ return new URL(uriReference);
22
+ } catch {
23
+ const parsedURL = new URL(uriReference, 'https://swagger.io');
24
+ const pathname = String(uriReference).startsWith('/') ? parsedURL.pathname : parsedURL.pathname.substring(1);
25
+ return {
26
+ hash: parsedURL.hash,
27
+ host: '',
28
+ hostname: '',
29
+ href: '',
30
+ origin: '',
31
+ password: '',
32
+ pathname,
33
+ port: '',
34
+ protocol: '',
35
+ search: parsedURL.search,
36
+ searchParams: parsedURL.searchParams
37
+ };
38
+ }
39
+ };
17
40
  const OperationNotFoundError = createError('OperationNotFoundError', function cb(message, extra, oriError) {
18
41
  this.originalError = oriError;
19
42
  Object.assign(this, extra || {});
@@ -47,30 +70,31 @@ export const self = {
47
70
  // pathName/method or operationId is optional
48
71
  export function execute(_ref) {
49
72
  let {
50
- http: userHttp,
51
- fetch,
52
- // This is legacy
53
- spec,
54
- operationId,
55
- pathName,
56
- method,
57
- parameters,
58
- securities
59
- } = _ref,
60
- extras = _objectWithoutProperties(_ref, _excluded);
73
+ http: userHttp,
74
+ fetch,
75
+ // This is legacy
76
+ spec,
77
+ operationId,
78
+ pathName,
79
+ method,
80
+ parameters,
81
+ securities,
82
+ ...extras
83
+ } = _ref;
61
84
  // Provide default fetch implementation
62
85
  const http = userHttp || fetch || stockHttp; // Default to _our_ http
63
86
 
64
87
  if (pathName && method && !operationId) {
65
88
  operationId = idFromPathMethodLegacy(pathName, method);
66
89
  }
67
- const request = self.buildRequest(_objectSpread({
90
+ const request = self.buildRequest({
68
91
  spec,
69
92
  operationId,
70
93
  parameters,
71
94
  securities,
72
- http
73
- }, extras));
95
+ http,
96
+ ...extras
97
+ });
74
98
  if (request.body && (isPlainObject(request.body) || Array.isArray(request.body))) {
75
99
  request.body = JSON.stringify(request.body);
76
100
  }
@@ -217,9 +241,10 @@ export function buildRequest(options) {
217
241
  });
218
242
 
219
243
  // Do version-specific tasks, then return those results.
220
- const versionSpecificOptions = _objectSpread(_objectSpread({}, options), {}, {
244
+ const versionSpecificOptions = {
245
+ ...options,
221
246
  operation
222
- });
247
+ };
223
248
  if (specIsOAS3) {
224
249
  req = oas3BuildRequest(versionSpecificOptions, req);
225
250
  } else {
@@ -258,6 +283,7 @@ export function baseUrl(obj) {
258
283
  return specIsOAS3 ? oas3BaseUrl(obj) : swagger2BaseUrl(obj);
259
284
  }
260
285
  function oas3BaseUrl(_ref2) {
286
+ var _spec$paths, _spec$paths2;
261
287
  let {
262
288
  spec,
263
289
  pathName,
@@ -266,7 +292,7 @@ function oas3BaseUrl(_ref2) {
266
292
  contextUrl,
267
293
  serverVariables = {}
268
294
  } = _ref2;
269
- const servers = getIn(spec, ['paths', pathName, (method || '').toLowerCase(), 'servers']) || getIn(spec, ['paths', pathName, 'servers']) || getIn(spec, ['servers']);
295
+ const servers = (spec === null || spec === void 0 || (_spec$paths = spec.paths) === null || _spec$paths === void 0 || (_spec$paths = _spec$paths[pathName]) === null || _spec$paths === void 0 || (_spec$paths = _spec$paths[(method || '').toLowerCase()]) === null || _spec$paths === void 0 ? void 0 : _spec$paths.servers) || (spec === null || spec === void 0 || (_spec$paths2 = spec.paths) === null || _spec$paths2 === void 0 || (_spec$paths2 = _spec$paths2[pathName]) === null || _spec$paths2 === void 0 ? void 0 : _spec$paths2.servers) || (spec === null || spec === void 0 ? void 0 : spec.servers);
270
296
  let selectedServerUrl = '';
271
297
  let selectedServerObj = null;
272
298
  if (server && servers && servers.length) {
@@ -300,11 +326,11 @@ function buildOas3UrlWithContext() {
300
326
  let ourUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
301
327
  let contextUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
302
328
  // relative server url should be resolved against contextUrl
303
- const parsedUrl = ourUrl && contextUrl ? url.parse(url.resolve(contextUrl, ourUrl)) : url.parse(ourUrl);
304
- const parsedContextUrl = url.parse(contextUrl);
305
- const computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol) || '';
329
+ const parsedUrl = ourUrl && contextUrl ? parseURIReference(url.resolve(contextUrl, ourUrl)) : parseURIReference(ourUrl);
330
+ const parsedContextUrl = parseURIReference(contextUrl);
331
+ const computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol);
306
332
  const computedHost = parsedUrl.host || parsedContextUrl.host;
307
- const computedPath = parsedUrl.pathname || '';
333
+ const computedPath = parsedUrl.pathname;
308
334
  let res;
309
335
  if (computedScheme && computedHost) {
310
336
  res = `${computedScheme}://${computedHost + computedPath}`;
@@ -334,7 +360,7 @@ function swagger2BaseUrl(_ref3) {
334
360
  scheme,
335
361
  contextUrl = ''
336
362
  } = _ref3;
337
- const parsedContextUrl = url.parse(contextUrl);
363
+ const parsedContextUrl = parseURIReference(contextUrl);
338
364
  const firstSchemeInSpec = Array.isArray(spec.schemes) ? spec.schemes[0] : null;
339
365
  const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http';
340
366
  const computedHost = spec.host || parsedContextUrl.host || '';
@@ -1,8 +1,6 @@
1
- import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
1
  // This function runs after the common function,
3
2
  // `src/execute/index.js#buildRequest`
4
3
  import { isPlainObject } from 'is-plain-object';
5
- import get from 'lodash/get';
6
4
  import btoa from '../../helpers/btoa.node.js';
7
5
  export default function buildRequest(options, req) {
8
6
  const {
@@ -63,7 +61,8 @@ export default function buildRequest(options, req) {
63
61
  // contentType that has been explicitly set
64
62
  if (requestContentType === 'application/x-www-form-urlencoded' || requestContentType === 'multipart/form-data') {
65
63
  if (typeof requestBody === 'object') {
66
- const encoding = requestBodyDef.content[requestContentType]?.encoding ?? {};
64
+ var _requestBodyDef$conte, _requestBodyDef$conte2;
65
+ const encoding = (_requestBodyDef$conte = (_requestBodyDef$conte2 = requestBodyDef.content[requestContentType]) === null || _requestBodyDef$conte2 === void 0 ? void 0 : _requestBodyDef$conte2.encoding) !== null && _requestBodyDef$conte !== void 0 ? _requestBodyDef$conte : {};
67
66
  req.form = {};
68
67
  Object.keys(requestBody).forEach(k => {
69
68
  req.form[k] = {
@@ -88,19 +87,22 @@ export default function buildRequest(options, req) {
88
87
  // Add security values, to operations - that declare their need on them
89
88
  // Adapted from the Swagger2 implementation
90
89
  export function applySecurities(_ref3) {
90
+ var _spec$components;
91
91
  let {
92
92
  request,
93
93
  securities = {},
94
94
  operation = {},
95
95
  spec
96
96
  } = _ref3;
97
- const result = _objectSpread({}, request);
97
+ const result = {
98
+ ...request
99
+ };
98
100
  const {
99
101
  authorized = {}
100
102
  } = securities;
101
103
  const security = operation.security || spec.security || [];
102
104
  const isAuthorized = authorized && !!Object.keys(authorized).length;
103
- const securityDef = get(spec, ['components', 'securitySchemes']) || {};
105
+ const securityDef = (spec === null || spec === void 0 || (_spec$components = spec.components) === null || _spec$components === void 0 ? void 0 : _spec$components.securitySchemes) || {};
104
106
  result.headers = result.headers || {};
105
107
  result.query = result.query || {};
106
108
  if (!Object.keys(securities).length || !isAuthorized || !security || Array.isArray(operation.security) && !operation.security.length) {
@@ -1,4 +1,3 @@
1
- import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
1
  import btoa from '../../helpers/btoa.node.js';
3
2
 
4
3
  // This function runs after the common function,
@@ -53,7 +52,9 @@ export function applySecurities(_ref) {
53
52
  operation = {},
54
53
  spec
55
54
  } = _ref;
56
- const result = _objectSpread({}, request);
55
+ const result = {
56
+ ...request
57
+ };
57
58
  const {
58
59
  authorized = {},
59
60
  specSecurity = []
@@ -0,0 +1,13 @@
1
+ import { fetch, Headers, Request, Response } from './fetch-ponyfill.browser.js';
2
+ if (typeof globalThis.fetch === 'undefined') {
3
+ globalThis.fetch = fetch;
4
+ }
5
+ if (typeof globalThis.Headers === 'undefined') {
6
+ globalThis.Headers = Headers;
7
+ }
8
+ if (typeof globalThis.Request === 'undefined') {
9
+ globalThis.Request = Request;
10
+ }
11
+ if (typeof globalThis.Response === 'undefined') {
12
+ globalThis.Response = Response;
13
+ }
@@ -0,0 +1,14 @@
1
+ import { fetch as fetchU, Headers as HeaderU, Request as RequestU, Response as ResponseU } from './fetch-ponyfill-undici.node.js';
2
+ import { fetch as fetchNF, Headers as HeadersNF, Request as RequestNF, Response as ResponseNF } from './fetch-ponyfill-node-fetch.node.js';
3
+ if (typeof globalThis.fetch === 'undefined') {
4
+ globalThis.fetch = fetchU || fetchNF;
5
+ }
6
+ if (typeof globalThis.Headers === 'undefined') {
7
+ globalThis.Headers = HeaderU || HeadersNF;
8
+ }
9
+ if (typeof globalThis.Request === 'undefined') {
10
+ globalThis.Request = RequestU || RequestNF;
11
+ }
12
+ if (typeof globalThis.Response === 'undefined') {
13
+ globalThis.Response = ResponseU || ResponseNF;
14
+ }
@@ -0,0 +1,3 @@
1
+ // we cannot use `node-fetch@3` as it's pure ESM package not compatible with CommonJS
2
+ import fetch, { Response, Headers, Request } from 'node-fetch-commonjs';
3
+ export { fetch, Response, Headers, Request };
@@ -0,0 +1,2 @@
1
+ import { fetch, Response, Headers, Request } from 'undici';
2
+ export { fetch, Response, Headers, Request };
@@ -0,0 +1,8 @@
1
+ // we're targeting browsers that already support fetch API
2
+ const {
3
+ fetch,
4
+ Response,
5
+ Headers,
6
+ Request
7
+ } = globalThis;
8
+ export { fetch, Response, Headers, Request };
package/es/http/index.js CHANGED
@@ -1,9 +1,8 @@
1
- import 'cross-fetch/polyfill';
2
1
  import qs from 'qs';
3
2
  import jsYaml from 'js-yaml';
4
3
  import { FormData, File, Blob } from 'formdata-node';
4
+ import '../helpers/fetch-polyfill.node.js';
5
5
  import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer.js';
6
- import foldFormDataToRequest from './fold-formdata-to-request.node.js';
7
6
 
8
7
  // For testing
9
8
  export const self = {
@@ -12,7 +11,7 @@ export const self = {
12
11
  };
13
12
 
14
13
  // Handles fetch-like syntax and the case where there is only one object passed-in
15
- // (which will have the URL as a property). Also serilizes the response.
14
+ // (which will have the URL as a property). Also serializes the response.
16
15
  export default async function http(url) {
17
16
  let request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
17
  if (typeof url === 'object') {
@@ -27,7 +26,7 @@ export default async function http(url) {
27
26
  self.mergeInQueryOrForm(request);
28
27
 
29
28
  // Newlines in header values cause weird error messages from `window.fetch`,
30
- // so let's massage them out.
29
+ // so let's message them out.
31
30
  // Context: https://stackoverflow.com/a/50709178
32
31
  if (request.headers) {
33
32
  Object.keys(request.headers).forEach(headerName => {
@@ -45,11 +44,12 @@ export default async function http(url) {
45
44
  request = (await request.requestInterceptor(request)) || request;
46
45
  }
47
46
 
48
- // for content-type=multipart\/form-data remove content-type from request before fetch
49
- // so that correct one with `boundary` is set when request body is different than boundary encoded string
47
+ /**
48
+ * For content-type=multipart/form-data remove content-type from request before fetch,
49
+ * so that correct one with `boundary` is set when request body is different from boundary encoded string.
50
+ */
50
51
  const contentType = request.headers['content-type'] || request.headers['Content-Type'];
51
- // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
52
- if (/multipart\/form-data/i.test(contentType) && request.body instanceof FormData) {
52
+ if (/multipart\/form-data/i.test(contentType)) {
53
53
  delete request.headers['content-type'];
54
54
  delete request.headers['Content-Type'];
55
55
  }
@@ -429,7 +429,8 @@ export function mergeInQueryOrForm() {
429
429
  const contentType = req.headers['content-type'] || req.headers['Content-Type'];
430
430
  if (hasFile || /multipart\/form-data/i.test(contentType)) {
431
431
  const formdata = buildFormData(req.form);
432
- foldFormDataToRequest(formdata, req);
432
+ req.formdata = formdata;
433
+ req.body = formdata;
433
434
  } else {
434
435
  req.body = encodeFormOrQuery(form);
435
436
  }
package/es/index.js CHANGED
@@ -1,6 +1,4 @@
1
- import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
1
  /* eslint-disable camelcase */
3
- import Url from 'url';
4
2
  import Http, { makeHttp, serializeRes, serializeHeaders } from './http/index.js';
5
3
  import { makeResolve } from './resolver/index.js';
6
4
  import { makeResolveSubtree } from './subtree-resolver/index.js';
@@ -88,7 +86,7 @@ Swagger.prototype = {
88
86
  http: Http,
89
87
  execute(options) {
90
88
  this.applyDefaults();
91
- return Swagger.execute(_objectSpread({
89
+ return Swagger.execute({
92
90
  spec: this.spec,
93
91
  http: this.http,
94
92
  securities: {
@@ -96,12 +94,13 @@ Swagger.prototype = {
96
94
  },
97
95
  contextUrl: typeof this.url === 'string' ? this.url : undefined,
98
96
  requestInterceptor: this.requestInterceptor || null,
99
- responseInterceptor: this.responseInterceptor || null
100
- }, options));
97
+ responseInterceptor: this.responseInterceptor || null,
98
+ ...options
99
+ });
101
100
  },
102
101
  resolve() {
103
102
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
104
- return Swagger.resolve(_objectSpread({
103
+ return Swagger.resolve({
105
104
  spec: this.spec,
106
105
  url: this.url,
107
106
  http: this.http || this.fetch,
@@ -109,8 +108,9 @@ Swagger.prototype = {
109
108
  useCircularStructures: this.useCircularStructures,
110
109
  requestInterceptor: this.requestInterceptor || null,
111
110
  responseInterceptor: this.responseInterceptor || null,
112
- skipNormalization: this.skipNormalization || false
113
- }, options)).then(obj => {
111
+ skipNormalization: this.skipNormalization || false,
112
+ ...options
113
+ }).then(obj => {
114
114
  this.originalSpec = this.spec;
115
115
  this.spec = obj.spec;
116
116
  this.errors = obj.errors;
@@ -125,7 +125,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
125
125
  const specUrl = this.url;
126
126
  // TODO: OAS3: support servers here
127
127
  if (specUrl && specUrl.startsWith('http')) {
128
- const parsed = Url.parse(specUrl);
128
+ const parsed = new URL(specUrl);
129
129
  if (!spec.host) {
130
130
  spec.host = parsed.host;
131
131
  }
package/es/interfaces.js CHANGED
@@ -1,4 +1,3 @@
1
- import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
1
  import { eachOperation, opId } from './helpers/index.js';
3
2
  const nullFn = () => null;
4
3
  const normalizeArray = arg => Array.isArray(arg) ? arg : [arg];
@@ -25,7 +24,7 @@ export function makeExecute() {
25
24
  responseInterceptor,
26
25
  userFetch
27
26
  } = swaggerJs;
28
- return swaggerJs.execute(_objectSpread({
27
+ return swaggerJs.execute({
29
28
  spec: swaggerJs.spec,
30
29
  requestInterceptor,
31
30
  responseInterceptor,
@@ -33,8 +32,9 @@ export function makeExecute() {
33
32
  pathName,
34
33
  method,
35
34
  parameters,
36
- operationId
37
- }, opts));
35
+ operationId,
36
+ ...opts
37
+ });
38
38
  };
39
39
  };
40
40
  }
@@ -36,9 +36,10 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = OpenApi3_1DereferenceStrategy
36
36
  },
37
37
  methods: {
38
38
  async dereference(file, options) {
39
+ var _options$dereference$;
39
40
  const visitors = [];
40
41
  const namespace = createNamespace(openApi3_1Namespace);
41
- const refSet = options.dereference.refSet ?? ReferenceSet();
42
+ const refSet = (_options$dereference$ = options.dereference.refSet) !== null && _options$dereference$ !== void 0 ? _options$dereference$ : ReferenceSet();
42
43
  let reference;
43
44
  if (!refSet.has(file.uri)) {
44
45
  reference = Reference({
@@ -18,9 +18,10 @@ const AllOfVisitor = compose({
18
18
 
19
19
  // collect error and return if allOf keyword is not an array
20
20
  if (!isArrayElement(schemaElement.allOf)) {
21
+ var _this$options$derefer, _this$options$derefer2;
21
22
  const error = new TypeError('allOf must be an array');
22
23
  error.fullPath = [...toPath([...ancestors, parent, schemaElement]), 'allOf'];
23
- this.options.dereference.dereferenceOpts?.errors?.push?.(error);
24
+ (_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, error);
24
25
  return undefined;
25
26
  }
26
27
 
@@ -32,9 +33,10 @@ const AllOfVisitor = compose({
32
33
  // collect errors if allOf keyword contains anything else than Schema Object
33
34
  const includesSchemaElementOnly = schemaElement.allOf.content.every(isSchemaElement);
34
35
  if (!includesSchemaElementOnly) {
36
+ var _this$options$derefer3, _this$options$derefer4;
35
37
  const error = new TypeError('Elements in allOf must be objects');
36
38
  error.fullPath = [...toPath([...ancestors, parent, schemaElement]), 'allOf'];
37
- this.options.dereference.dereferenceOpts?.errors?.push?.(error);
39
+ (_this$options$derefer3 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer3 === void 0 || (_this$options$derefer3 = _this$options$derefer3.errors) === null || _this$options$derefer3 === void 0 || (_this$options$derefer4 = _this$options$derefer3.push) === null || _this$options$derefer4 === void 0 || _this$options$derefer4.call(_this$options$derefer3, error);
38
40
  return undefined;
39
41
  }
40
42
  const mergedSchemaElement = deepmerge.all([...schemaElement.allOf.content, schemaElement]);
@@ -33,6 +33,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
33
33
  methods: {
34
34
  async ReferenceElement(referenceElement, key, parent, path, ancestors) {
35
35
  try {
36
+ var _this$basePath, _referenceElement$$re, _referenceElement$des, _referenceElement$sum;
36
37
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
37
38
 
38
39
  // skip already identified cycled Path Item Objects
@@ -112,7 +113,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
112
113
  ancestors: ancestorsLineage,
113
114
  allowMetaPatches: this.allowMetaPatches,
114
115
  useCircularStructures: this.useCircularStructures,
115
- basePath: this.basePath ?? [...toPath([...ancestors, parent, referenceElement]), '$ref']
116
+ basePath: (_this$basePath = this.basePath) !== null && _this$basePath !== void 0 ? _this$basePath : [...toPath([...ancestors, parent, referenceElement]), '$ref']
116
117
  });
117
118
  fragment = await visitAsync(fragment, visitor, {
118
119
  keyMap,
@@ -124,9 +125,9 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
124
125
  this.indirections.pop();
125
126
  fragment = fragment.clone();
126
127
  fragment.setMetaProperty('ref-fields', {
127
- $ref: referenceElement.$ref?.toValue(),
128
- description: referenceElement.description?.toValue(),
129
- summary: referenceElement.summary?.toValue()
128
+ $ref: (_referenceElement$$re = referenceElement.$ref) === null || _referenceElement$$re === void 0 ? void 0 : _referenceElement$$re.toValue(),
129
+ description: (_referenceElement$des = referenceElement.description) === null || _referenceElement$des === void 0 ? void 0 : _referenceElement$des.toValue(),
130
+ summary: (_referenceElement$sum = referenceElement.summary) === null || _referenceElement$sum === void 0 ? void 0 : _referenceElement$sum.toValue()
130
131
  });
131
132
  // annotate fragment with info about origin
132
133
  fragment.setMetaProperty('ref-origin', reference.uri);
@@ -154,19 +155,21 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
154
155
  // transclude the element for a fragment
155
156
  return fragment;
156
157
  } catch (error) {
158
+ var _this$basePath2, _this$options$derefer, _this$options$derefer2;
157
159
  const rootCause = getRootCause(error);
158
160
  const wrappedError = wrapError(rootCause, {
159
161
  baseDoc: this.reference.uri,
160
162
  $ref: referenceElement.$ref.toValue(),
161
163
  pointer: uriToPointer(referenceElement.$ref.toValue()),
162
- fullPath: this.basePath ?? [...toPath([...ancestors, parent, referenceElement]), '$ref']
164
+ fullPath: (_this$basePath2 = this.basePath) !== null && _this$basePath2 !== void 0 ? _this$basePath2 : [...toPath([...ancestors, parent, referenceElement]), '$ref']
163
165
  });
164
- this.options.dereference.dereferenceOpts?.errors?.push?.(wrappedError);
166
+ (_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, wrappedError);
165
167
  return undefined;
166
168
  }
167
169
  },
168
170
  async PathItemElement(pathItemElement, key, parent, path, ancestors) {
169
171
  try {
172
+ var _this$basePath3, _pathItemElement$$ref;
170
173
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
171
174
 
172
175
  // ignore PathItemElement without $ref field
@@ -242,7 +245,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
242
245
  ancestors: ancestorsLineage,
243
246
  allowMetaPatches: this.allowMetaPatches,
244
247
  useCircularStructures: this.useCircularStructures,
245
- basePath: this.basePath ?? [...toPath([...ancestors, parent, pathItemElement]), '$ref']
248
+ basePath: (_this$basePath3 = this.basePath) !== null && _this$basePath3 !== void 0 ? _this$basePath3 : [...toPath([...ancestors, parent, pathItemElement]), '$ref']
246
249
  });
247
250
  referencedElement = await visitAsync(referencedElement, visitor, {
248
251
  keyMap,
@@ -264,7 +267,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
264
267
 
265
268
  // annotate referenced element with info about original referencing element
266
269
  mergedPathItemElement.setMetaProperty('ref-fields', {
267
- $ref: pathItemElement.$ref?.toValue()
270
+ $ref: (_pathItemElement$$ref = pathItemElement.$ref) === null || _pathItemElement$$ref === void 0 ? void 0 : _pathItemElement$$ref.toValue()
268
271
  });
269
272
  // annotate referenced element with info about origin
270
273
  mergedPathItemElement.setMetaProperty('ref-origin', reference.uri);
@@ -281,19 +284,21 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
281
284
  // transclude referencing element with merged referenced element
282
285
  return mergedPathItemElement;
283
286
  } catch (error) {
287
+ var _this$basePath4, _this$options$derefer3, _this$options$derefer4;
284
288
  const rootCause = getRootCause(error);
285
289
  const wrappedError = wrapError(rootCause, {
286
290
  baseDoc: this.reference.uri,
287
291
  $ref: pathItemElement.$ref.toValue(),
288
292
  pointer: uriToPointer(pathItemElement.$ref.toValue()),
289
- fullPath: this.basePath ?? [...toPath([...ancestors, parent, pathItemElement]), '$ref']
293
+ fullPath: (_this$basePath4 = this.basePath) !== null && _this$basePath4 !== void 0 ? _this$basePath4 : [...toPath([...ancestors, parent, pathItemElement]), '$ref']
290
294
  });
291
- this.options.dereference.dereferenceOpts?.errors?.push?.(wrappedError);
295
+ (_this$options$derefer3 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer3 === void 0 || (_this$options$derefer3 = _this$options$derefer3.errors) === null || _this$options$derefer3 === void 0 || (_this$options$derefer4 = _this$options$derefer3.push) === null || _this$options$derefer4 === void 0 || _this$options$derefer4.call(_this$options$derefer3, wrappedError);
292
296
  return undefined;
293
297
  }
294
298
  },
295
299
  async SchemaElement(referencingElement, key, parent, path, ancestors) {
296
300
  try {
301
+ var _this$basePath5, _referencingElement$$2;
297
302
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
298
303
 
299
304
  // skip current referencing schema as $ref keyword was not defined
@@ -412,7 +417,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
412
417
  useCircularStructures: this.useCircularStructures,
413
418
  allowMetaPatches: this.allowMetaPatches,
414
419
  ancestors: ancestorsLineage,
415
- basePath: this.basePath ?? [...toPath([...ancestors, parent, referencingElement]), '$ref']
420
+ basePath: (_this$basePath5 = this.basePath) !== null && _this$basePath5 !== void 0 ? _this$basePath5 : [...toPath([...ancestors, parent, referencingElement]), '$ref']
416
421
  });
417
422
  referencedElement = await visitAsync(referencedElement, mergeVisitor, {
418
423
  keyMap,
@@ -423,11 +428,12 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
423
428
  directAncestors.delete(referencingElement);
424
429
  this.indirections.pop();
425
430
  if (isBooleanJsonSchemaElement(referencedElement)) {
431
+ var _referencingElement$$;
426
432
  // Boolean JSON Schema
427
433
  const jsonSchemaBooleanElement = referencedElement.clone();
428
434
  // annotate referenced element with info about original referencing element
429
435
  jsonSchemaBooleanElement.setMetaProperty('ref-fields', {
430
- $ref: referencingElement.$ref?.toValue()
436
+ $ref: (_referencingElement$$ = referencingElement.$ref) === null || _referencingElement$$ === void 0 ? void 0 : _referencingElement$$.toValue()
431
437
  });
432
438
  // annotate referenced element with info about origin
433
439
  jsonSchemaBooleanElement.setMetaProperty('ref-origin', retrievalURI);
@@ -445,7 +451,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
445
451
 
446
452
  // annotate referenced element with info about original referencing element
447
453
  mergedSchemaElement.setMetaProperty('ref-fields', {
448
- $ref: referencingElement.$ref?.toValue()
454
+ $ref: (_referencingElement$$2 = referencingElement.$ref) === null || _referencingElement$$2 === void 0 ? void 0 : _referencingElement$$2.toValue()
449
455
  });
450
456
  // annotate fragment with info about origin
451
457
  mergedSchemaElement.setMetaProperty('ref-origin', retrievalURI);
@@ -462,13 +468,14 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
462
468
  // transclude referencing element with merged referenced element
463
469
  return mergedSchemaElement;
464
470
  } catch (error) {
471
+ var _this$basePath6, _this$options$derefer5, _this$options$derefer6;
465
472
  const rootCause = getRootCause(error);
466
473
  const wrappedError = new SchemaRefError(`Could not resolve reference: ${rootCause.message}`, {
467
474
  baseDoc: this.reference.uri,
468
475
  $ref: referencingElement.$ref.toValue(),
469
- fullPath: this.basePath ?? [...toPath([...ancestors, parent, referencingElement]), '$ref']
476
+ fullPath: (_this$basePath6 = this.basePath) !== null && _this$basePath6 !== void 0 ? _this$basePath6 : [...toPath([...ancestors, parent, referencingElement]), '$ref']
470
477
  }, rootCause);
471
- this.options.dereference.dereferenceOpts?.errors?.push?.(wrappedError);
478
+ (_this$options$derefer5 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer5 === void 0 || (_this$options$derefer5 = _this$options$derefer5.errors) === null || _this$options$derefer5 === void 0 || (_this$options$derefer6 = _this$options$derefer5.push) === null || _this$options$derefer6 === void 0 || _this$options$derefer6.call(_this$options$derefer5, wrappedError);
472
479
  return undefined;
473
480
  }
474
481
  },
@@ -484,13 +491,14 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
484
491
  try {
485
492
  return await OpenApi3_1DereferenceVisitor.compose.methods.ExampleElement.call(this, exampleElement, key, parent, path, ancestors);
486
493
  } catch (error) {
494
+ var _exampleElement$exter, _this$basePath7, _this$options$derefer7, _this$options$derefer8;
487
495
  const rootCause = getRootCause(error);
488
496
  const wrappedError = wrapError(rootCause, {
489
497
  baseDoc: this.reference.uri,
490
- externalValue: exampleElement.externalValue?.toValue(),
491
- fullPath: this.basePath ?? [...toPath([...ancestors, parent, exampleElement]), 'externalValue']
498
+ externalValue: (_exampleElement$exter = exampleElement.externalValue) === null || _exampleElement$exter === void 0 ? void 0 : _exampleElement$exter.toValue(),
499
+ fullPath: (_this$basePath7 = this.basePath) !== null && _this$basePath7 !== void 0 ? _this$basePath7 : [...toPath([...ancestors, parent, exampleElement]), 'externalValue']
492
500
  });
493
- this.options.dereference.dereferenceOpts?.errors?.push?.(wrappedError);
501
+ (_this$options$derefer7 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer7 === void 0 || (_this$options$derefer7 = _this$options$derefer7.errors) === null || _this$options$derefer7 === void 0 || (_this$options$derefer8 = _this$options$derefer7.push) === null || _this$options$derefer8 === void 0 || _this$options$derefer8.call(_this$options$derefer7, wrappedError);
494
502
  return undefined;
495
503
  }
496
504
  }
@@ -30,11 +30,12 @@ const ParameterMacroVisitor = compose({
30
30
  const macroValue = this.parameterMacro(pojoOperation, pojoParameter);
31
31
  parameterElement.set('default', macroValue);
32
32
  } catch (error) {
33
+ var _this$options$derefer, _this$options$derefer2;
33
34
  const macroError = new Error(error, {
34
35
  cause: error
35
36
  });
36
37
  macroError.fullPath = toPath([...ancestors, parent]);
37
- this.options.dereference.dereferenceOpts?.errors?.push?.(macroError);
38
+ (_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
38
39
  }
39
40
  }
40
41
  }
@@ -23,11 +23,12 @@ const ModelPropertyMacroVisitor = compose({
23
23
  const macroValue = this.modelPropertyMacro(toValue(property));
24
24
  property.set('default', macroValue);
25
25
  } catch (error) {
26
+ var _this$options$derefer, _this$options$derefer2;
26
27
  const macroError = new Error(error, {
27
28
  cause: error
28
29
  });
29
30
  macroError.fullPath = [...toPath([...ancestors, parent, schemaElement]), 'properties'];
30
- this.options.dereference.dereferenceOpts?.errors?.push?.(macroError);
31
+ (_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
31
32
  }
32
33
  });
33
34
  }