swagger-client 3.20.2 → 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 (35) hide show
  1. package/README.md +19 -2
  2. package/dist/swagger-client.browser.js +2615 -2275
  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 +35 -8
  6. package/es/execute/oas3/build-request.js +2 -2
  7. package/es/helpers/fetch-polyfill.browser.js +13 -0
  8. package/es/helpers/fetch-polyfill.node.js +14 -0
  9. package/es/helpers/fetch-ponyfill-node-fetch.node.js +3 -0
  10. package/es/helpers/fetch-ponyfill-undici.node.js +2 -0
  11. package/es/helpers/fetch-ponyfill.browser.js +8 -0
  12. package/es/http/index.js +10 -9
  13. package/es/index.js +1 -2
  14. package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +5 -4
  15. package/es/specmap/helpers.js +2 -2
  16. package/es/specmap/lib/refs.js +2 -2
  17. package/es/subtree-resolver/index.js +1 -2
  18. package/lib/execute/index.js +35 -8
  19. package/lib/execute/oas3/build-request.js +2 -2
  20. package/lib/helpers/fetch-polyfill.browser.js +15 -0
  21. package/lib/helpers/fetch-polyfill.node.js +16 -0
  22. package/lib/helpers/fetch-ponyfill-node-fetch.node.js +9 -0
  23. package/lib/helpers/fetch-ponyfill-undici.node.js +8 -0
  24. package/lib/helpers/fetch-ponyfill.browser.js +15 -0
  25. package/lib/http/index.js +10 -9
  26. package/lib/index.js +2 -3
  27. package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +6 -5
  28. package/lib/specmap/helpers.js +2 -2
  29. package/lib/specmap/lib/refs.js +3 -3
  30. package/lib/subtree-resolver/index.js +1 -2
  31. package/package.json +11 -17
  32. package/es/http/fold-formdata-to-request.browser.js +0 -4
  33. package/es/http/fold-formdata-to-request.node.js +0 -31
  34. package/lib/http/fold-formdata-to-request.browser.js +0 -9
  35. package/lib/http/fold-formdata-to-request.node.js +0 -35
@@ -1,7 +1,6 @@
1
- import getIn from 'lodash/get';
2
- import url from 'url';
3
1
  import cookie from 'cookie';
4
2
  import { isPlainObject } from 'is-plain-object';
3
+ import { url } from '@swagger-api/apidom-reference/configuration/empty';
5
4
  import stockHttp, { mergeInQueryOrForm } from '../http/index.js';
6
5
  import createError from '../specmap/lib/create-error.js';
7
6
  import SWAGGER2_PARAMETER_BUILDERS from './swagger2/parameter-builders.js';
@@ -11,6 +10,33 @@ import swagger2BuildRequest from './swagger2/build-request.js';
11
10
  import { getOperationRaw, idFromPathMethodLegacy } from '../helpers/index.js';
12
11
  import { isOpenAPI3 } from '../helpers/openapi-predicates.js';
13
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
+ };
14
40
  const OperationNotFoundError = createError('OperationNotFoundError', function cb(message, extra, oriError) {
15
41
  this.originalError = oriError;
16
42
  Object.assign(this, extra || {});
@@ -257,6 +283,7 @@ export function baseUrl(obj) {
257
283
  return specIsOAS3 ? oas3BaseUrl(obj) : swagger2BaseUrl(obj);
258
284
  }
259
285
  function oas3BaseUrl(_ref2) {
286
+ var _spec$paths, _spec$paths2;
260
287
  let {
261
288
  spec,
262
289
  pathName,
@@ -265,7 +292,7 @@ function oas3BaseUrl(_ref2) {
265
292
  contextUrl,
266
293
  serverVariables = {}
267
294
  } = _ref2;
268
- 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);
269
296
  let selectedServerUrl = '';
270
297
  let selectedServerObj = null;
271
298
  if (server && servers && servers.length) {
@@ -299,11 +326,11 @@ function buildOas3UrlWithContext() {
299
326
  let ourUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
300
327
  let contextUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
301
328
  // relative server url should be resolved against contextUrl
302
- const parsedUrl = ourUrl && contextUrl ? url.parse(url.resolve(contextUrl, ourUrl)) : url.parse(ourUrl);
303
- const parsedContextUrl = url.parse(contextUrl);
304
- 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);
305
332
  const computedHost = parsedUrl.host || parsedContextUrl.host;
306
- const computedPath = parsedUrl.pathname || '';
333
+ const computedPath = parsedUrl.pathname;
307
334
  let res;
308
335
  if (computedScheme && computedHost) {
309
336
  res = `${computedScheme}://${computedHost + computedPath}`;
@@ -333,7 +360,7 @@ function swagger2BaseUrl(_ref3) {
333
360
  scheme,
334
361
  contextUrl = ''
335
362
  } = _ref3;
336
- const parsedContextUrl = url.parse(contextUrl);
363
+ const parsedContextUrl = parseURIReference(contextUrl);
337
364
  const firstSchemeInSpec = Array.isArray(spec.schemes) ? spec.schemes[0] : null;
338
365
  const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http';
339
366
  const computedHost = spec.host || parsedContextUrl.host || '';
@@ -1,7 +1,6 @@
1
1
  // This function runs after the common function,
2
2
  // `src/execute/index.js#buildRequest`
3
3
  import { isPlainObject } from 'is-plain-object';
4
- import get from 'lodash/get';
5
4
  import btoa from '../../helpers/btoa.node.js';
6
5
  export default function buildRequest(options, req) {
7
6
  const {
@@ -88,6 +87,7 @@ 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 = {},
@@ -102,7 +102,7 @@ export function applySecurities(_ref3) {
102
102
  } = securities;
103
103
  const security = operation.security || spec.security || [];
104
104
  const isAuthorized = authorized && !!Object.keys(authorized).length;
105
- 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) || {};
106
106
  result.headers = result.headers || {};
107
107
  result.query = result.query || {};
108
108
  if (!Object.keys(securities).length || !isAuthorized || !security || Array.isArray(operation.security) && !operation.security.length) {
@@ -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,5 +1,4 @@
1
1
  /* eslint-disable camelcase */
2
- import Url from 'url';
3
2
  import Http, { makeHttp, serializeRes, serializeHeaders } from './http/index.js';
4
3
  import { makeResolve } from './resolver/index.js';
5
4
  import { makeResolveSubtree } from './subtree-resolver/index.js';
@@ -126,7 +125,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
126
125
  const specUrl = this.url;
127
126
  // TODO: OAS3: support servers here
128
127
  if (specUrl && specUrl.startsWith('http')) {
129
- const parsed = Url.parse(specUrl);
128
+ const parsed = new URL(specUrl);
130
129
  if (!spec.host) {
131
130
  spec.host = parsed.host;
132
131
  }
@@ -1,5 +1,6 @@
1
- import 'cross-fetch/polyfill';
1
+ import AbortController from 'abort-controller';
2
2
  import { ResolverError, HttpResolver } from '@swagger-api/apidom-reference/configuration/empty';
3
+ import '../../../../../../helpers/fetch-polyfill.node.js';
3
4
  import Http from '../../../../../../http/index.js';
4
5
  const HttpResolverSwaggerClient = HttpResolver.compose({
5
6
  props: {
@@ -27,7 +28,7 @@ const HttpResolverSwaggerClient = HttpResolver.compose({
27
28
  controller.abort();
28
29
  }, this.timeout);
29
30
  const credentials = this.getHttpClient().withCredentials || this.withCredentials ? 'include' : 'same-origin';
30
- const redirects = this.redirects === 0 ? 'error' : 'follow';
31
+ const redirect = this.redirects === 0 ? 'error' : 'follow';
31
32
  const follow = this.redirects > 0 ? this.redirects : undefined;
32
33
  try {
33
34
  const response = await client({
@@ -36,7 +37,7 @@ const HttpResolverSwaggerClient = HttpResolver.compose({
36
37
  userFetch: async (resource, options) => {
37
38
  let res = await fetch(resource, options);
38
39
  try {
39
- // node-fetch supports mutations
40
+ // undici supports mutations
40
41
  res.headers.delete('Content-Type');
41
42
  } catch {
42
43
  // Fetch API has guards which prevent mutations
@@ -49,7 +50,7 @@ const HttpResolverSwaggerClient = HttpResolver.compose({
49
50
  return res;
50
51
  },
51
52
  credentials,
52
- redirects,
53
+ redirect,
53
54
  follow,
54
55
  ...this.swaggerHTTPClientConfig
55
56
  });
@@ -1,5 +1,5 @@
1
1
  import traverse from 'traverse';
2
- import URL from 'url';
2
+ import { url } from '@swagger-api/apidom-reference/configuration/empty';
3
3
 
4
4
  // This will match if the direct parent's key exactly matches an item.
5
5
  const freelyNamedKeyParents = ['properties'];
@@ -51,6 +51,6 @@ export function generateAbsoluteRefPatches(obj, basePath) {
51
51
  }
52
52
  export function absolutifyPointer(pointer, baseUrl) {
53
53
  const [urlPart, fragmentPart] = pointer.split('#');
54
- const newRefUrlPart = URL.resolve(urlPart || '', baseUrl || '');
54
+ const newRefUrlPart = url.resolve(baseUrl || '', urlPart || '');
55
55
  return fragmentPart ? `${newRefUrlPart}#${fragmentPart}` : newRefUrlPart;
56
56
  }
@@ -1,6 +1,6 @@
1
- import 'cross-fetch/polyfill';
2
1
  import jsYaml from 'js-yaml';
3
- import url from 'url';
2
+ import { url } from '@swagger-api/apidom-reference/configuration/empty';
3
+ import '../../helpers/fetch-polyfill.node.js';
4
4
  import lib from './index.js';
5
5
  import createError from './create-error.js';
6
6
  import { isFreelyNamed, absolutifyPointer } from '../helpers.js';
@@ -20,7 +20,6 @@
20
20
  // future versions.
21
21
  //
22
22
  // TODO: move the remarks above into project documentation
23
- import get from 'lodash/get';
24
23
  import resolve from '../resolver/index.js';
25
24
  import genericResolverStrategy from '../resolver/strategies/generic/index.js';
26
25
  import openApi2ResolverStrategy from '../resolver/strategies/openapi-2/index.js';
@@ -57,7 +56,7 @@ const resolveSubtree = async function (obj, path) {
57
56
  skipNormalization: true
58
57
  });
59
58
  if (!returnEntireTree && Array.isArray(path) && path.length) {
60
- result.spec = get(result.spec, path) || null;
59
+ result.spec = path.reduce((acc, pathSegment) => acc === null || acc === void 0 ? void 0 : acc[pathSegment], result.spec) || null;
61
60
  }
62
61
  return result;
63
62
  };
@@ -7,10 +7,9 @@ exports.baseUrl = baseUrl;
7
7
  exports.buildRequest = buildRequest;
8
8
  exports.execute = execute;
9
9
  exports.self = void 0;
10
- var _get = _interopRequireDefault(require("lodash/get"));
11
- var _url = _interopRequireDefault(require("url"));
12
10
  var _cookie = _interopRequireDefault(require("cookie"));
13
11
  var _isPlainObject = require("is-plain-object");
12
+ var _empty = require("@swagger-api/apidom-reference/configuration/empty");
14
13
  var _index = _interopRequireWildcard(require("../http/index.js"));
15
14
  var _createError = _interopRequireDefault(require("../specmap/lib/create-error.js"));
16
15
  var _parameterBuilders = _interopRequireDefault(require("./swagger2/parameter-builders.js"));
@@ -20,6 +19,33 @@ var _buildRequest2 = _interopRequireDefault(require("./swagger2/build-request.js
20
19
  var _index2 = require("../helpers/index.js");
21
20
  var _openapiPredicates = require("../helpers/openapi-predicates.js");
22
21
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
22
+
23
+ /**
24
+ * `parseURIReference` function simulates the behavior of `node:url` parse function.
25
+ * New WHATWG URL API is not capable of parsing relative references natively,
26
+ * but can be adapter by utilizing the `base` parameter.
27
+ */
28
+ const parseURIReference = uriReference => {
29
+ try {
30
+ return new URL(uriReference);
31
+ } catch {
32
+ const parsedURL = new URL(uriReference, 'https://swagger.io');
33
+ const pathname = String(uriReference).startsWith('/') ? parsedURL.pathname : parsedURL.pathname.substring(1);
34
+ return {
35
+ hash: parsedURL.hash,
36
+ host: '',
37
+ hostname: '',
38
+ href: '',
39
+ origin: '',
40
+ password: '',
41
+ pathname,
42
+ port: '',
43
+ protocol: '',
44
+ search: parsedURL.search,
45
+ searchParams: parsedURL.searchParams
46
+ };
47
+ }
48
+ };
23
49
  const OperationNotFoundError = (0, _createError.default)('OperationNotFoundError', function cb(message, extra, oriError) {
24
50
  this.originalError = oriError;
25
51
  Object.assign(this, extra || {});
@@ -267,6 +293,7 @@ function baseUrl(obj) {
267
293
  return specIsOAS3 ? oas3BaseUrl(obj) : swagger2BaseUrl(obj);
268
294
  }
269
295
  function oas3BaseUrl(_ref2) {
296
+ var _spec$paths, _spec$paths2;
270
297
  let {
271
298
  spec,
272
299
  pathName,
@@ -275,7 +302,7 @@ function oas3BaseUrl(_ref2) {
275
302
  contextUrl,
276
303
  serverVariables = {}
277
304
  } = _ref2;
278
- const servers = (0, _get.default)(spec, ['paths', pathName, (method || '').toLowerCase(), 'servers']) || (0, _get.default)(spec, ['paths', pathName, 'servers']) || (0, _get.default)(spec, ['servers']);
305
+ const servers = (spec == null || (_spec$paths = spec.paths) == null || (_spec$paths = _spec$paths[pathName]) == null || (_spec$paths = _spec$paths[(method || '').toLowerCase()]) == null ? void 0 : _spec$paths.servers) || (spec == null || (_spec$paths2 = spec.paths) == null || (_spec$paths2 = _spec$paths2[pathName]) == null ? void 0 : _spec$paths2.servers) || (spec == null ? void 0 : spec.servers);
279
306
  let selectedServerUrl = '';
280
307
  let selectedServerObj = null;
281
308
  if (server && servers && servers.length) {
@@ -313,11 +340,11 @@ function buildOas3UrlWithContext(ourUrl, contextUrl) {
313
340
  contextUrl = '';
314
341
  }
315
342
  // relative server url should be resolved against contextUrl
316
- const parsedUrl = ourUrl && contextUrl ? _url.default.parse(_url.default.resolve(contextUrl, ourUrl)) : _url.default.parse(ourUrl);
317
- const parsedContextUrl = _url.default.parse(contextUrl);
318
- const computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol) || '';
343
+ const parsedUrl = ourUrl && contextUrl ? parseURIReference(_empty.url.resolve(contextUrl, ourUrl)) : parseURIReference(ourUrl);
344
+ const parsedContextUrl = parseURIReference(contextUrl);
345
+ const computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol);
319
346
  const computedHost = parsedUrl.host || parsedContextUrl.host;
320
- const computedPath = parsedUrl.pathname || '';
347
+ const computedPath = parsedUrl.pathname;
321
348
  let res;
322
349
  if (computedScheme && computedHost) {
323
350
  res = `${computedScheme}://${computedHost + computedPath}`;
@@ -347,7 +374,7 @@ function swagger2BaseUrl(_ref3) {
347
374
  scheme,
348
375
  contextUrl = ''
349
376
  } = _ref3;
350
- const parsedContextUrl = _url.default.parse(contextUrl);
377
+ const parsedContextUrl = parseURIReference(contextUrl);
351
378
  const firstSchemeInSpec = Array.isArray(spec.schemes) ? spec.schemes[0] : null;
352
379
  const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http';
353
380
  const computedHost = spec.host || parsedContextUrl.host || '';
@@ -5,7 +5,6 @@ exports.__esModule = true;
5
5
  exports.applySecurities = applySecurities;
6
6
  exports.default = buildRequest;
7
7
  var _isPlainObject = require("is-plain-object");
8
- var _get = _interopRequireDefault(require("lodash/get"));
9
8
  var _btoaNode = _interopRequireDefault(require("../../helpers/btoa.node.js"));
10
9
  // This function runs after the common function,
11
10
  // `src/execute/index.js#buildRequest`
@@ -95,6 +94,7 @@ function buildRequest(options, req) {
95
94
  // Add security values, to operations - that declare their need on them
96
95
  // Adapted from the Swagger2 implementation
97
96
  function applySecurities(_ref3) {
97
+ var _spec$components;
98
98
  let {
99
99
  request,
100
100
  securities = {},
@@ -109,7 +109,7 @@ function applySecurities(_ref3) {
109
109
  } = securities;
110
110
  const security = operation.security || spec.security || [];
111
111
  const isAuthorized = authorized && !!Object.keys(authorized).length;
112
- const securityDef = (0, _get.default)(spec, ['components', 'securitySchemes']) || {};
112
+ const securityDef = (spec == null || (_spec$components = spec.components) == null ? void 0 : _spec$components.securitySchemes) || {};
113
113
  result.headers = result.headers || {};
114
114
  result.query = result.query || {};
115
115
  if (!Object.keys(securities).length || !isAuthorized || !security || Array.isArray(operation.security) && !operation.security.length) {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _fetchPonyfillBrowser = require("./fetch-ponyfill.browser.js");
4
+ if (typeof globalThis.fetch === 'undefined') {
5
+ globalThis.fetch = _fetchPonyfillBrowser.fetch;
6
+ }
7
+ if (typeof globalThis.Headers === 'undefined') {
8
+ globalThis.Headers = _fetchPonyfillBrowser.Headers;
9
+ }
10
+ if (typeof globalThis.Request === 'undefined') {
11
+ globalThis.Request = _fetchPonyfillBrowser.Request;
12
+ }
13
+ if (typeof globalThis.Response === 'undefined') {
14
+ globalThis.Response = _fetchPonyfillBrowser.Response;
15
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _fetchPonyfillUndiciNode = require("./fetch-ponyfill-undici.node.js");
4
+ var _fetchPonyfillNodeFetchNode = require("./fetch-ponyfill-node-fetch.node.js");
5
+ if (typeof globalThis.fetch === 'undefined') {
6
+ globalThis.fetch = _fetchPonyfillUndiciNode.fetch || _fetchPonyfillNodeFetchNode.fetch;
7
+ }
8
+ if (typeof globalThis.Headers === 'undefined') {
9
+ globalThis.Headers = _fetchPonyfillUndiciNode.Headers || _fetchPonyfillNodeFetchNode.Headers;
10
+ }
11
+ if (typeof globalThis.Request === 'undefined') {
12
+ globalThis.Request = _fetchPonyfillUndiciNode.Request || _fetchPonyfillNodeFetchNode.Request;
13
+ }
14
+ if (typeof globalThis.Response === 'undefined') {
15
+ globalThis.Response = _fetchPonyfillUndiciNode.Response || _fetchPonyfillNodeFetchNode.Response;
16
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
+ exports.__esModule = true;
5
+ var _nodeFetchCommonjs = _interopRequireWildcard(require("node-fetch-commonjs"));
6
+ exports.fetch = _nodeFetchCommonjs.default;
7
+ exports.Response = _nodeFetchCommonjs.Response;
8
+ exports.Headers = _nodeFetchCommonjs.Headers;
9
+ exports.Request = _nodeFetchCommonjs.Request;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _undici = require("undici");
5
+ exports.fetch = _undici.fetch;
6
+ exports.Response = _undici.Response;
7
+ exports.Headers = _undici.Headers;
8
+ exports.Request = _undici.Request;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.fetch = exports.Response = exports.Request = exports.Headers = void 0;
5
+ // we're targeting browsers that already support fetch API
6
+ const {
7
+ fetch,
8
+ Response,
9
+ Headers,
10
+ Request
11
+ } = globalThis;
12
+ exports.Request = Request;
13
+ exports.Headers = Headers;
14
+ exports.Response = Response;
15
+ exports.fetch = fetch;
package/lib/http/index.js CHANGED
@@ -11,12 +11,11 @@ exports.self = void 0;
11
11
  exports.serializeHeaders = serializeHeaders;
12
12
  exports.serializeRes = serializeRes;
13
13
  exports.shouldDownloadAsText = void 0;
14
- require("cross-fetch/polyfill");
15
14
  var _qs = _interopRequireDefault(require("qs"));
16
15
  var _jsYaml = _interopRequireDefault(require("js-yaml"));
17
16
  var _formdataNode = require("formdata-node");
17
+ require("../helpers/fetch-polyfill.node.js");
18
18
  var _styleSerializer = require("../execute/oas3/style-serializer.js");
19
- var _foldFormdataToRequestNode = _interopRequireDefault(require("./fold-formdata-to-request.node.js"));
20
19
  // For testing
21
20
  const self = {
22
21
  serializeRes,
@@ -24,7 +23,7 @@ const self = {
24
23
  };
25
24
 
26
25
  // Handles fetch-like syntax and the case where there is only one object passed-in
27
- // (which will have the URL as a property). Also serilizes the response.
26
+ // (which will have the URL as a property). Also serializes the response.
28
27
  exports.self = self;
29
28
  async function http(url, request) {
30
29
  if (request === void 0) {
@@ -42,7 +41,7 @@ async function http(url, request) {
42
41
  self.mergeInQueryOrForm(request);
43
42
 
44
43
  // Newlines in header values cause weird error messages from `window.fetch`,
45
- // so let's massage them out.
44
+ // so let's message them out.
46
45
  // Context: https://stackoverflow.com/a/50709178
47
46
  if (request.headers) {
48
47
  Object.keys(request.headers).forEach(headerName => {
@@ -60,11 +59,12 @@ async function http(url, request) {
60
59
  request = (await request.requestInterceptor(request)) || request;
61
60
  }
62
61
 
63
- // for content-type=multipart\/form-data remove content-type from request before fetch
64
- // so that correct one with `boundary` is set when request body is different than boundary encoded string
62
+ /**
63
+ * For content-type=multipart/form-data remove content-type from request before fetch,
64
+ * so that correct one with `boundary` is set when request body is different from boundary encoded string.
65
+ */
65
66
  const contentType = request.headers['content-type'] || request.headers['Content-Type'];
66
- // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
67
- if (/multipart\/form-data/i.test(contentType) && request.body instanceof _formdataNode.FormData) {
67
+ if (/multipart\/form-data/i.test(contentType)) {
68
68
  delete request.headers['content-type'];
69
69
  delete request.headers['Content-Type'];
70
70
  }
@@ -457,7 +457,8 @@ function mergeInQueryOrForm(req) {
457
457
  const contentType = req.headers['content-type'] || req.headers['Content-Type'];
458
458
  if (hasFile || /multipart\/form-data/i.test(contentType)) {
459
459
  const formdata = buildFormData(req.form);
460
- (0, _foldFormdataToRequestNode.default)(formdata, req);
460
+ req.formdata = formdata;
461
+ req.body = formdata;
461
462
  } else {
462
463
  req.body = encodeFormOrQuery(form);
463
464
  }
package/lib/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
5
  exports.__esModule = true;
6
6
  exports.helpers = exports.default = void 0;
7
- var _url = _interopRequireDefault(require("url"));
8
7
  var _index = _interopRequireWildcard(require("./http/index.js"));
9
8
  var _index2 = require("./resolver/index.js");
10
9
  var _index3 = require("./subtree-resolver/index.js");
@@ -137,7 +136,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
137
136
  const specUrl = this.url;
138
137
  // TODO: OAS3: support servers here
139
138
  if (specUrl && specUrl.startsWith('http')) {
140
- const parsed = _url.default.parse(specUrl);
139
+ const parsed = new URL(specUrl);
141
140
  if (!spec.host) {
142
141
  spec.host = parsed.host;
143
142
  }
@@ -3,8 +3,9 @@
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
5
  exports.default = void 0;
6
- require("cross-fetch/polyfill");
6
+ var _abortController = _interopRequireDefault(require("abort-controller"));
7
7
  var _empty = require("@swagger-api/apidom-reference/configuration/empty");
8
+ require("../../../../../../helpers/fetch-polyfill.node.js");
8
9
  var _index = _interopRequireDefault(require("../../../../../../http/index.js"));
9
10
  const HttpResolverSwaggerClient = _empty.HttpResolver.compose({
10
11
  props: {
@@ -24,7 +25,7 @@ const HttpResolverSwaggerClient = _empty.HttpResolver.compose({
24
25
  },
25
26
  async read(file) {
26
27
  const client = this.getHttpClient();
27
- const controller = new AbortController();
28
+ const controller = new _abortController.default();
28
29
  const {
29
30
  signal
30
31
  } = controller;
@@ -32,7 +33,7 @@ const HttpResolverSwaggerClient = _empty.HttpResolver.compose({
32
33
  controller.abort();
33
34
  }, this.timeout);
34
35
  const credentials = this.getHttpClient().withCredentials || this.withCredentials ? 'include' : 'same-origin';
35
- const redirects = this.redirects === 0 ? 'error' : 'follow';
36
+ const redirect = this.redirects === 0 ? 'error' : 'follow';
36
37
  const follow = this.redirects > 0 ? this.redirects : undefined;
37
38
  try {
38
39
  const response = await client({
@@ -41,7 +42,7 @@ const HttpResolverSwaggerClient = _empty.HttpResolver.compose({
41
42
  userFetch: async (resource, options) => {
42
43
  let res = await fetch(resource, options);
43
44
  try {
44
- // node-fetch supports mutations
45
+ // undici supports mutations
45
46
  res.headers.delete('Content-Type');
46
47
  } catch {
47
48
  // Fetch API has guards which prevent mutations
@@ -54,7 +55,7 @@ const HttpResolverSwaggerClient = _empty.HttpResolver.compose({
54
55
  return res;
55
56
  },
56
57
  credentials,
57
- redirects,
58
+ redirect,
58
59
  follow,
59
60
  ...this.swaggerHTTPClientConfig
60
61
  });
@@ -6,7 +6,7 @@ exports.absolutifyPointer = absolutifyPointer;
6
6
  exports.generateAbsoluteRefPatches = generateAbsoluteRefPatches;
7
7
  exports.isFreelyNamed = isFreelyNamed;
8
8
  var _traverse = _interopRequireDefault(require("traverse"));
9
- var _url = _interopRequireDefault(require("url"));
9
+ var _empty = require("@swagger-api/apidom-reference/configuration/empty");
10
10
  // This will match if the direct parent's key exactly matches an item.
11
11
  const freelyNamedKeyParents = ['properties'];
12
12
 
@@ -57,6 +57,6 @@ function generateAbsoluteRefPatches(obj, basePath, _temp) {
57
57
  }
58
58
  function absolutifyPointer(pointer, baseUrl) {
59
59
  const [urlPart, fragmentPart] = pointer.split('#');
60
- const newRefUrlPart = _url.default.resolve(urlPart || '', baseUrl || '');
60
+ const newRefUrlPart = _empty.url.resolve(baseUrl || '', urlPart || '');
61
61
  return fragmentPart ? `${newRefUrlPart}#${fragmentPart}` : newRefUrlPart;
62
62
  }