swagger-client 3.20.2 → 3.22.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.
- package/README.md +19 -2
- package/dist/swagger-client.browser.js +2632 -2303
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/index.js +35 -8
- package/es/execute/oas3/build-request.js +2 -2
- package/es/helpers/fetch-polyfill.browser.js +22 -0
- package/es/helpers/fetch-polyfill.node.js +23 -0
- package/es/helpers/fetch-ponyfill-node-fetch.node.js +3 -0
- package/es/helpers/fetch-ponyfill-undici.node.js +4 -0
- package/es/helpers/fetch-ponyfill.browser.js +11 -0
- package/es/http/index.js +10 -10
- package/es/index.js +1 -2
- package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +5 -4
- package/es/specmap/helpers.js +2 -2
- package/es/specmap/lib/refs.js +2 -2
- package/es/subtree-resolver/index.js +1 -2
- package/lib/execute/index.js +35 -8
- package/lib/execute/oas3/build-request.js +2 -2
- package/lib/helpers/fetch-polyfill.browser.js +24 -0
- package/lib/helpers/fetch-polyfill.node.js +25 -0
- package/lib/helpers/fetch-ponyfill-node-fetch.node.js +12 -0
- package/lib/helpers/fetch-ponyfill-undici.node.js +14 -0
- package/lib/helpers/fetch-ponyfill.browser.js +21 -0
- package/lib/http/index.js +16 -16
- package/lib/index.js +2 -3
- package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +6 -5
- package/lib/specmap/helpers.js +2 -2
- package/lib/specmap/lib/refs.js +3 -3
- package/lib/subtree-resolver/index.js +1 -2
- package/package.json +11 -18
- package/es/http/fold-formdata-to-request.browser.js +0 -4
- package/es/http/fold-formdata-to-request.node.js +0 -31
- package/lib/http/fold-formdata-to-request.browser.js +0 -9
- package/lib/http/fold-formdata-to-request.node.js +0 -35
package/es/execute/index.js
CHANGED
|
@@ -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 =
|
|
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 ?
|
|
303
|
-
const parsedContextUrl =
|
|
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 =
|
|
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 =
|
|
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,22 @@
|
|
|
1
|
+
import { fetch, Headers, Request, Response, FormData, File, Blob } 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
|
+
}
|
|
14
|
+
if (typeof globalThis.FormData === 'undefined') {
|
|
15
|
+
globalThis.FormData = FormData;
|
|
16
|
+
}
|
|
17
|
+
if (typeof globalThis.File === 'undefined') {
|
|
18
|
+
globalThis.File = File;
|
|
19
|
+
}
|
|
20
|
+
if (typeof globalThis.Blob === 'undefined') {
|
|
21
|
+
globalThis.Blob = Blob;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fetch as fetchU, Headers as HeaderU, Request as RequestU, Response as ResponseU, FormData as FormDataU, File as FileU, Blob as BlobU } from './fetch-ponyfill-undici.node.js';
|
|
2
|
+
import { fetch as fetchNF, Headers as HeadersNF, Request as RequestNF, Response as ResponseNF, FormData as FormDataNF, File as FileNF, Blob as BlobNF } 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
|
+
}
|
|
15
|
+
if (typeof globalThis.FormData === 'undefined') {
|
|
16
|
+
globalThis.FormData = FormDataU || FormDataNF;
|
|
17
|
+
}
|
|
18
|
+
if (typeof globalThis.File === 'undefined') {
|
|
19
|
+
globalThis.File = FileU || FileNF;
|
|
20
|
+
}
|
|
21
|
+
if (typeof globalThis.Blob === 'undefined') {
|
|
22
|
+
globalThis.Blob = BlobU || BlobNF;
|
|
23
|
+
}
|
package/es/http/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import 'cross-fetch/polyfill';
|
|
2
1
|
import qs from 'qs';
|
|
3
2
|
import jsYaml from 'js-yaml';
|
|
4
|
-
import
|
|
3
|
+
import '../helpers/fetch-polyfill.node.js';
|
|
5
4
|
import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer.js';
|
|
6
|
-
import foldFormDataToRequest from './fold-formdata-to-request.node.js';
|
|
7
5
|
|
|
8
6
|
// For testing
|
|
9
7
|
export const self = {
|
|
@@ -12,7 +10,7 @@ export const self = {
|
|
|
12
10
|
};
|
|
13
11
|
|
|
14
12
|
// 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
|
|
13
|
+
// (which will have the URL as a property). Also serializes the response.
|
|
16
14
|
export default async function http(url) {
|
|
17
15
|
let request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
16
|
if (typeof url === 'object') {
|
|
@@ -27,7 +25,7 @@ export default async function http(url) {
|
|
|
27
25
|
self.mergeInQueryOrForm(request);
|
|
28
26
|
|
|
29
27
|
// Newlines in header values cause weird error messages from `window.fetch`,
|
|
30
|
-
// so let's
|
|
28
|
+
// so let's message them out.
|
|
31
29
|
// Context: https://stackoverflow.com/a/50709178
|
|
32
30
|
if (request.headers) {
|
|
33
31
|
Object.keys(request.headers).forEach(headerName => {
|
|
@@ -45,11 +43,12 @@ export default async function http(url) {
|
|
|
45
43
|
request = (await request.requestInterceptor(request)) || request;
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
/**
|
|
47
|
+
* For content-type=multipart/form-data remove content-type from request before fetch,
|
|
48
|
+
* so that correct one with `boundary` is set when request body is different from boundary encoded string.
|
|
49
|
+
*/
|
|
50
50
|
const contentType = request.headers['content-type'] || request.headers['Content-Type'];
|
|
51
|
-
|
|
52
|
-
if (/multipart\/form-data/i.test(contentType) && request.body instanceof FormData) {
|
|
51
|
+
if (/multipart\/form-data/i.test(contentType)) {
|
|
53
52
|
delete request.headers['content-type'];
|
|
54
53
|
delete request.headers['Content-Type'];
|
|
55
54
|
}
|
|
@@ -429,7 +428,8 @@ export function mergeInQueryOrForm() {
|
|
|
429
428
|
const contentType = req.headers['content-type'] || req.headers['Content-Type'];
|
|
430
429
|
if (hasFile || /multipart\/form-data/i.test(contentType)) {
|
|
431
430
|
const formdata = buildFormData(req.form);
|
|
432
|
-
|
|
431
|
+
req.formdata = formdata;
|
|
432
|
+
req.body = formdata;
|
|
433
433
|
} else {
|
|
434
434
|
req.body = encodeFormOrQuery(form);
|
|
435
435
|
}
|
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 =
|
|
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 '
|
|
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
|
|
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
|
-
//
|
|
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
|
-
|
|
53
|
+
redirect,
|
|
53
54
|
follow,
|
|
54
55
|
...this.swaggerHTTPClientConfig
|
|
55
56
|
});
|
package/es/specmap/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import traverse from 'traverse';
|
|
2
|
-
import
|
|
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 =
|
|
54
|
+
const newRefUrlPart = url.resolve(baseUrl || '', urlPart || '');
|
|
55
55
|
return fragmentPart ? `${newRefUrlPart}#${fragmentPart}` : newRefUrlPart;
|
|
56
56
|
}
|
package/es/specmap/lib/refs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import 'cross-fetch/polyfill';
|
|
2
1
|
import jsYaml from 'js-yaml';
|
|
3
|
-
import url from '
|
|
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 =
|
|
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
|
};
|
package/lib/execute/index.js
CHANGED
|
@@ -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 = (
|
|
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 ?
|
|
317
|
-
const parsedContextUrl =
|
|
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 =
|
|
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 = (
|
|
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,24 @@
|
|
|
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
|
+
}
|
|
16
|
+
if (typeof globalThis.FormData === 'undefined') {
|
|
17
|
+
globalThis.FormData = _fetchPonyfillBrowser.FormData;
|
|
18
|
+
}
|
|
19
|
+
if (typeof globalThis.File === 'undefined') {
|
|
20
|
+
globalThis.File = _fetchPonyfillBrowser.File;
|
|
21
|
+
}
|
|
22
|
+
if (typeof globalThis.Blob === 'undefined') {
|
|
23
|
+
globalThis.Blob = _fetchPonyfillBrowser.Blob;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
17
|
+
if (typeof globalThis.FormData === 'undefined') {
|
|
18
|
+
globalThis.FormData = _fetchPonyfillUndiciNode.FormData || _fetchPonyfillNodeFetchNode.FormData;
|
|
19
|
+
}
|
|
20
|
+
if (typeof globalThis.File === 'undefined') {
|
|
21
|
+
globalThis.File = _fetchPonyfillUndiciNode.File || _fetchPonyfillNodeFetchNode.File;
|
|
22
|
+
}
|
|
23
|
+
if (typeof globalThis.Blob === 'undefined') {
|
|
24
|
+
globalThis.Blob = _fetchPonyfillUndiciNode.Blob || _fetchPonyfillNodeFetchNode.Blob;
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
10
|
+
exports.FormData = _nodeFetchCommonjs.FormData;
|
|
11
|
+
exports.File = _nodeFetchCommonjs.File;
|
|
12
|
+
exports.Blob = _nodeFetchCommonjs.Blob;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.Blob = void 0;
|
|
5
|
+
var _buffer = require("buffer");
|
|
6
|
+
var _undici = require("undici");
|
|
7
|
+
exports.fetch = _undici.fetch;
|
|
8
|
+
exports.Response = _undici.Response;
|
|
9
|
+
exports.Headers = _undici.Headers;
|
|
10
|
+
exports.Request = _undici.Request;
|
|
11
|
+
exports.FormData = _undici.FormData;
|
|
12
|
+
exports.File = _undici.File;
|
|
13
|
+
const BlobU = typeof _undici.fetch === 'undefined' ? undefined : _buffer.Blob;
|
|
14
|
+
exports.Blob = BlobU;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.fetch = exports.Response = exports.Request = exports.Headers = exports.FormData = exports.File = exports.Blob = void 0;
|
|
5
|
+
// we're targeting browsers that already support fetch API
|
|
6
|
+
const {
|
|
7
|
+
fetch,
|
|
8
|
+
Response,
|
|
9
|
+
Headers,
|
|
10
|
+
Request,
|
|
11
|
+
FormData,
|
|
12
|
+
File,
|
|
13
|
+
Blob
|
|
14
|
+
} = globalThis;
|
|
15
|
+
exports.Blob = Blob;
|
|
16
|
+
exports.File = File;
|
|
17
|
+
exports.FormData = FormData;
|
|
18
|
+
exports.Request = Request;
|
|
19
|
+
exports.Headers = Headers;
|
|
20
|
+
exports.Response = Response;
|
|
21
|
+
exports.fetch = fetch;
|
package/lib/http/index.js
CHANGED
|
@@ -11,12 +11,10 @@ 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
|
+
require("../helpers/fetch-polyfill.node.js");
|
|
18
17
|
var _styleSerializer = require("../execute/oas3/style-serializer.js");
|
|
19
|
-
var _foldFormdataToRequestNode = _interopRequireDefault(require("./fold-formdata-to-request.node.js"));
|
|
20
18
|
// For testing
|
|
21
19
|
const self = {
|
|
22
20
|
serializeRes,
|
|
@@ -24,7 +22,7 @@ const self = {
|
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
// 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
|
|
25
|
+
// (which will have the URL as a property). Also serializes the response.
|
|
28
26
|
exports.self = self;
|
|
29
27
|
async function http(url, request) {
|
|
30
28
|
if (request === void 0) {
|
|
@@ -42,7 +40,7 @@ async function http(url, request) {
|
|
|
42
40
|
self.mergeInQueryOrForm(request);
|
|
43
41
|
|
|
44
42
|
// Newlines in header values cause weird error messages from `window.fetch`,
|
|
45
|
-
// so let's
|
|
43
|
+
// so let's message them out.
|
|
46
44
|
// Context: https://stackoverflow.com/a/50709178
|
|
47
45
|
if (request.headers) {
|
|
48
46
|
Object.keys(request.headers).forEach(headerName => {
|
|
@@ -60,11 +58,12 @@ async function http(url, request) {
|
|
|
60
58
|
request = (await request.requestInterceptor(request)) || request;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
/**
|
|
62
|
+
* For content-type=multipart/form-data remove content-type from request before fetch,
|
|
63
|
+
* so that correct one with `boundary` is set when request body is different from boundary encoded string.
|
|
64
|
+
*/
|
|
65
65
|
const contentType = request.headers['content-type'] || request.headers['Content-Type'];
|
|
66
|
-
|
|
67
|
-
if (/multipart\/form-data/i.test(contentType) && request.body instanceof _formdataNode.FormData) {
|
|
66
|
+
if (/multipart\/form-data/i.test(contentType)) {
|
|
68
67
|
delete request.headers['content-type'];
|
|
69
68
|
delete request.headers['Content-Type'];
|
|
70
69
|
}
|
|
@@ -176,10 +175,10 @@ function isFile(obj, navigatorObj) {
|
|
|
176
175
|
}
|
|
177
176
|
return false;
|
|
178
177
|
}
|
|
179
|
-
if (typeof
|
|
178
|
+
if (typeof File !== 'undefined' && obj instanceof File) {
|
|
180
179
|
return true;
|
|
181
180
|
}
|
|
182
|
-
if (typeof
|
|
181
|
+
if (typeof Blob !== 'undefined' && obj instanceof Blob) {
|
|
183
182
|
return true;
|
|
184
183
|
}
|
|
185
184
|
if (ArrayBuffer.isView(obj)) {
|
|
@@ -210,7 +209,7 @@ const SEPARATORS = {
|
|
|
210
209
|
* This sub-class is exclusively used only when Encoding Object
|
|
211
210
|
* is defined within the Media Type Object (OpenAPI 3.x.y).
|
|
212
211
|
*/
|
|
213
|
-
class FileWithData extends
|
|
212
|
+
class FileWithData extends File {
|
|
214
213
|
constructor(data, name, options) {
|
|
215
214
|
if (name === void 0) {
|
|
216
215
|
name = '';
|
|
@@ -386,21 +385,21 @@ function buildFormData(reqForm) {
|
|
|
386
385
|
// eslint-disable-next-line no-restricted-syntax
|
|
387
386
|
for (const v of value) {
|
|
388
387
|
if (ArrayBuffer.isView(v)) {
|
|
389
|
-
const blob = new
|
|
388
|
+
const blob = new Blob([v]);
|
|
390
389
|
formData.append(key, blob);
|
|
391
390
|
} else {
|
|
392
391
|
formData.append(key, v);
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
} else if (ArrayBuffer.isView(value)) {
|
|
396
|
-
const blob = new
|
|
395
|
+
const blob = new Blob([value]);
|
|
397
396
|
formData.append(key, blob);
|
|
398
397
|
} else {
|
|
399
398
|
formData.append(key, value);
|
|
400
399
|
}
|
|
401
400
|
}
|
|
402
401
|
return formData;
|
|
403
|
-
}, new
|
|
402
|
+
}, new FormData());
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
// Encodes an object using appropriate serializer.
|
|
@@ -457,7 +456,8 @@ function mergeInQueryOrForm(req) {
|
|
|
457
456
|
const contentType = req.headers['content-type'] || req.headers['Content-Type'];
|
|
458
457
|
if (hasFile || /multipart\/form-data/i.test(contentType)) {
|
|
459
458
|
const formdata = buildFormData(req.form);
|
|
460
|
-
|
|
459
|
+
req.formdata = formdata;
|
|
460
|
+
req.body = formdata;
|
|
461
461
|
} else {
|
|
462
462
|
req.body = encodeFormOrQuery(form);
|
|
463
463
|
}
|