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.
- package/README.md +19 -2
- package/dist/swagger-client.browser.js +13796 -16135
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/index.js +53 -27
- package/es/execute/oas3/build-request.js +7 -5
- package/es/execute/swagger2/build-request.js +3 -2
- package/es/helpers/fetch-polyfill.browser.js +13 -0
- package/es/helpers/fetch-polyfill.node.js +14 -0
- package/es/helpers/fetch-ponyfill-node-fetch.node.js +3 -0
- package/es/helpers/fetch-ponyfill-undici.node.js +2 -0
- package/es/helpers/fetch-ponyfill.browser.js +8 -0
- package/es/http/index.js +10 -9
- package/es/index.js +9 -9
- package/es/interfaces.js +4 -4
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +2 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +4 -2
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +26 -18
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +2 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +2 -1
- package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +12 -10
- package/es/resolver/index.js +7 -4
- package/es/resolver/strategies/openapi-3-1-apidom/normalize.js +1 -1
- package/es/specmap/helpers.js +2 -2
- package/es/specmap/index.js +6 -4
- package/es/specmap/lib/all-of.js +3 -2
- package/es/specmap/lib/context-tree.js +4 -2
- package/es/specmap/lib/index.js +11 -5
- package/es/specmap/lib/parameters.js +3 -2
- package/es/specmap/lib/properties.js +3 -2
- package/es/specmap/lib/refs.js +2 -2
- package/es/subtree-resolver/index.js +8 -6
- package/lib/execute/index.js +77 -49
- package/lib/execute/oas3/build-request.js +22 -18
- package/lib/execute/oas3/parameter-builders.js +26 -23
- package/lib/execute/oas3/style-serializer.js +27 -23
- package/lib/execute/swagger2/build-request.js +11 -13
- package/lib/execute/swagger2/parameter-builders.js +29 -24
- package/lib/helpers/fetch-polyfill.browser.js +15 -0
- package/lib/helpers/fetch-polyfill.node.js +16 -0
- package/lib/helpers/fetch-ponyfill-node-fetch.node.js +9 -0
- package/lib/helpers/fetch-ponyfill-undici.node.js +8 -0
- package/lib/helpers/fetch-ponyfill.browser.js +15 -0
- package/lib/helpers/find-operation.js +1 -1
- package/lib/helpers/get-operation-raw.js +7 -6
- package/lib/helpers/id-from-path-method/index.js +5 -4
- package/lib/helpers/index.js +2 -2
- package/lib/helpers/op-id.js +8 -4
- package/lib/http/index.js +52 -22
- package/lib/index.js +21 -18
- package/lib/interfaces.js +49 -36
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +1 -1
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +12 -12
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +1 -1
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +9 -8
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +29 -28
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +8 -7
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +8 -7
- package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +1 -2
- package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +1 -2
- package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +18 -19
- package/lib/resolver/index.js +9 -11
- package/lib/resolver/strategies/generic/index.js +5 -4
- package/lib/resolver/strategies/generic/normalize.js +1 -1
- package/lib/resolver/strategies/generic/resolve.js +2 -3
- package/lib/resolver/strategies/openapi-2/index.js +9 -7
- package/lib/resolver/strategies/openapi-2/normalize.js +2 -2
- package/lib/resolver/strategies/openapi-2/resolve.js +1 -1
- package/lib/resolver/strategies/openapi-3-0/index.js +9 -7
- package/lib/resolver/strategies/openapi-3-0/normalize.js +2 -2
- package/lib/resolver/strategies/openapi-3-0/resolve.js +1 -1
- package/lib/resolver/strategies/openapi-3-1-apidom/index.js +10 -9
- package/lib/resolver/strategies/openapi-3-1-apidom/normalize.js +2 -2
- package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +2 -3
- package/lib/resolver/utils/index.js +4 -1
- package/lib/resolver/utils/options.js +1 -1
- package/lib/specmap/helpers.js +9 -8
- package/lib/specmap/index.js +15 -11
- package/lib/specmap/lib/all-of.js +3 -6
- package/lib/specmap/lib/context-tree.js +4 -6
- package/lib/specmap/lib/create-error.js +4 -1
- package/lib/specmap/lib/index.js +13 -12
- package/lib/specmap/lib/parameters.js +4 -7
- package/lib/specmap/lib/properties.js +4 -7
- package/lib/specmap/lib/refs.js +4 -4
- package/lib/subtree-resolver/index.js +19 -13
- package/package.json +17 -26
- package/es/http/fold-formdata-to-request.browser.js +0 -4
- package/es/http/fold-formdata-to-request.node.js +0 -29
- package/lib/http/fold-formdata-to-request.browser.js +0 -9
- package/lib/http/fold-formdata-to-request.node.js +0 -37
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import 'cross-fetch/polyfill';
|
|
1
|
+
import AbortController from 'abort-controller';
|
|
3
2
|
import { ResolverError, HttpResolver } from '@swagger-api/apidom-reference/configuration/empty';
|
|
3
|
+
import '../../../../../../helpers/fetch-polyfill.node.js';
|
|
4
4
|
import Http from '../../../../../../http/index.js';
|
|
5
5
|
const HttpResolverSwaggerClient = HttpResolver.compose({
|
|
6
6
|
props: {
|
|
@@ -28,30 +28,32 @@ const HttpResolverSwaggerClient = HttpResolver.compose({
|
|
|
28
28
|
controller.abort();
|
|
29
29
|
}, this.timeout);
|
|
30
30
|
const credentials = this.getHttpClient().withCredentials || this.withCredentials ? 'include' : 'same-origin';
|
|
31
|
-
const
|
|
31
|
+
const redirect = this.redirects === 0 ? 'error' : 'follow';
|
|
32
32
|
const follow = this.redirects > 0 ? this.redirects : undefined;
|
|
33
33
|
try {
|
|
34
|
-
const response = await client(
|
|
34
|
+
const response = await client({
|
|
35
35
|
url: file.uri,
|
|
36
36
|
signal,
|
|
37
37
|
userFetch: async (resource, options) => {
|
|
38
38
|
let res = await fetch(resource, options);
|
|
39
39
|
try {
|
|
40
|
-
//
|
|
40
|
+
// undici supports mutations
|
|
41
41
|
res.headers.delete('Content-Type');
|
|
42
42
|
} catch {
|
|
43
43
|
// Fetch API has guards which prevent mutations
|
|
44
|
-
res = new Response(res.body,
|
|
44
|
+
res = new Response(res.body, {
|
|
45
|
+
...res,
|
|
45
46
|
headers: new Headers(res.headers)
|
|
46
|
-
})
|
|
47
|
+
});
|
|
47
48
|
res.headers.delete('Content-Type');
|
|
48
49
|
}
|
|
49
50
|
return res;
|
|
50
51
|
},
|
|
51
52
|
credentials,
|
|
52
|
-
|
|
53
|
-
follow
|
|
54
|
-
|
|
53
|
+
redirect,
|
|
54
|
+
follow,
|
|
55
|
+
...this.swaggerHTTPClientConfig
|
|
56
|
+
});
|
|
55
57
|
return response.text.arrayBuffer();
|
|
56
58
|
} catch (error) {
|
|
57
59
|
throw new ResolverError(`Error downloading "${file.uri}"`, {
|
package/es/resolver/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import { makeFetchJSON } from './utils/index.js';
|
|
3
2
|
import * as optionsUtil from './utils/options.js';
|
|
4
3
|
import genericStrategy from './strategies/generic/index.js';
|
|
@@ -16,14 +15,18 @@ const resolve = async options => {
|
|
|
16
15
|
requestInterceptor,
|
|
17
16
|
responseInterceptor
|
|
18
17
|
})(retrievalURI));
|
|
19
|
-
const strategyOptions =
|
|
18
|
+
const strategyOptions = {
|
|
19
|
+
...options,
|
|
20
20
|
spec: retrievedSpec
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
const strategy = options.strategies.find(strg => strg.match(strategyOptions));
|
|
23
23
|
return strategy.resolve(strategyOptions);
|
|
24
24
|
};
|
|
25
25
|
export const makeResolve = defaultOptions => async options => {
|
|
26
|
-
const mergedOptions =
|
|
26
|
+
const mergedOptions = {
|
|
27
|
+
...defaultOptions,
|
|
28
|
+
...options
|
|
29
|
+
};
|
|
27
30
|
return resolve(mergedOptions);
|
|
28
31
|
};
|
|
29
32
|
export default makeResolve({
|
|
@@ -29,7 +29,7 @@ const normalize = element => {
|
|
|
29
29
|
* Plain Old JavaScript Objects and returns Plain Old JavaScript Objects.
|
|
30
30
|
*/
|
|
31
31
|
export const pojoAdapter = normalizeFn => spec => {
|
|
32
|
-
if (spec
|
|
32
|
+
if (spec !== null && spec !== void 0 && spec.$$normalized) return spec;
|
|
33
33
|
if (pojoAdapter.cache.has(spec)) return spec;
|
|
34
34
|
const openApiElement = OpenApi3_1Element.refract(spec);
|
|
35
35
|
const normalized = normalizeFn(openApiElement);
|
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/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import lib from './lib/index.js';
|
|
3
2
|
import refs from './lib/refs.js';
|
|
4
3
|
import allOf from './lib/all-of.js';
|
|
@@ -210,7 +209,9 @@ class SpecMap {
|
|
|
210
209
|
}
|
|
211
210
|
updateMutations(patch) {
|
|
212
211
|
if (typeof patch.value === 'object' && !Array.isArray(patch.value) && this.allowMetaPatches) {
|
|
213
|
-
patch.value =
|
|
212
|
+
patch.value = {
|
|
213
|
+
...patch.value
|
|
214
|
+
};
|
|
214
215
|
}
|
|
215
216
|
const result = lib.applyPatch(this.state, patch, {
|
|
216
217
|
allowMetaPatches: this.allowMetaPatches
|
|
@@ -230,9 +231,10 @@ class SpecMap {
|
|
|
230
231
|
}
|
|
231
232
|
promisedPatchThen(patch) {
|
|
232
233
|
patch.value = patch.value.then(val => {
|
|
233
|
-
const promisedPatch =
|
|
234
|
+
const promisedPatch = {
|
|
235
|
+
...patch,
|
|
234
236
|
value: val
|
|
235
|
-
}
|
|
237
|
+
};
|
|
236
238
|
this.removePromisedPatch(patch);
|
|
237
239
|
this.updatePatches(promisedPatch);
|
|
238
240
|
}).catch(e => {
|
package/es/specmap/lib/all-of.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import { isFreelyNamed, generateAbsoluteRefPatches } from '../helpers.js';
|
|
3
2
|
export default {
|
|
4
3
|
key: 'allOf',
|
|
@@ -27,7 +26,9 @@ export default {
|
|
|
27
26
|
if (!originalDefinitionObj) return; // bail out if we've lost sight of our target
|
|
28
27
|
originalDefinitionObj = originalDefinitionObj[part];
|
|
29
28
|
});
|
|
30
|
-
originalDefinitionObj =
|
|
29
|
+
originalDefinitionObj = {
|
|
30
|
+
...originalDefinitionObj
|
|
31
|
+
};
|
|
31
32
|
|
|
32
33
|
// when we've lost sight, interrupt prematurely
|
|
33
34
|
if (Object.keys(originalDefinitionObj).length === 0) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
export default class ContextTree {
|
|
3
2
|
constructor(value) {
|
|
4
3
|
this.root = createNode(value || {});
|
|
@@ -72,7 +71,10 @@ function createNode(value, parent) {
|
|
|
72
71
|
}
|
|
73
72
|
function updateNode(node, value, parent) {
|
|
74
73
|
node.value = value || {};
|
|
75
|
-
node.protoValue = parent ?
|
|
74
|
+
node.protoValue = parent ? {
|
|
75
|
+
...parent.protoValue,
|
|
76
|
+
...node.value
|
|
77
|
+
} : node.value;
|
|
76
78
|
Object.keys(node.children).forEach(prop => {
|
|
77
79
|
const child = node.children[prop];
|
|
78
80
|
node.children[prop] = updateNode(child, child.value, node);
|
package/es/specmap/lib/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import * as jsonPatch from 'fast-json-patch';
|
|
3
2
|
import deepmerge from 'deepmerge';
|
|
4
3
|
export default {
|
|
@@ -29,9 +28,10 @@ export default {
|
|
|
29
28
|
};
|
|
30
29
|
function applyPatch(obj, patch, opts) {
|
|
31
30
|
opts = opts || {};
|
|
32
|
-
patch =
|
|
31
|
+
patch = {
|
|
32
|
+
...patch,
|
|
33
33
|
path: patch.path && normalizeJSONPath(patch.path)
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
if (patch.op === 'merge') {
|
|
36
36
|
const newValue = getInByJsonPath(obj, patch.path);
|
|
37
37
|
Object.assign(newValue, patch.value);
|
|
@@ -60,7 +60,10 @@ function applyPatch(obj, patch, opts) {
|
|
|
60
60
|
value
|
|
61
61
|
} = patch;
|
|
62
62
|
if (opts.allowMetaPatches && patch.meta && isAdditiveMutation(patch) && (Array.isArray(patch.value) || isObject(patch.value))) {
|
|
63
|
-
value =
|
|
63
|
+
value = {
|
|
64
|
+
...value,
|
|
65
|
+
...patch.meta
|
|
66
|
+
};
|
|
64
67
|
}
|
|
65
68
|
obj = value;
|
|
66
69
|
} else {
|
|
@@ -69,7 +72,10 @@ function applyPatch(obj, patch, opts) {
|
|
|
69
72
|
// Attach metadata to the resulting value.
|
|
70
73
|
if (opts.allowMetaPatches && patch.meta && isAdditiveMutation(patch) && (Array.isArray(patch.value) || isObject(patch.value))) {
|
|
71
74
|
const currentValue = getInByJsonPath(obj, patch.path);
|
|
72
|
-
const newValue =
|
|
75
|
+
const newValue = {
|
|
76
|
+
...currentValue,
|
|
77
|
+
...patch.meta
|
|
78
|
+
};
|
|
73
79
|
jsonPatch.applyPatch(obj, [replace(patch.path, newValue)]);
|
|
74
80
|
}
|
|
75
81
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import lib from './index.js';
|
|
3
2
|
export default {
|
|
4
3
|
key: 'parameters',
|
|
@@ -6,7 +5,9 @@ export default {
|
|
|
6
5
|
if (Array.isArray(parameters) && parameters.length) {
|
|
7
6
|
const val = Object.assign([], parameters);
|
|
8
7
|
const opPath = fullPath.slice(0, -1);
|
|
9
|
-
const op =
|
|
8
|
+
const op = {
|
|
9
|
+
...lib.getIn(specmap.spec, opPath)
|
|
10
|
+
};
|
|
10
11
|
for (let i = 0; i < parameters.length; i += 1) {
|
|
11
12
|
const param = parameters[i];
|
|
12
13
|
try {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
import lib from './index.js';
|
|
3
2
|
export default {
|
|
4
3
|
key: 'properties',
|
|
5
4
|
plugin: (properties, key, fullPath, specmap) => {
|
|
6
|
-
const val =
|
|
5
|
+
const val = {
|
|
6
|
+
...properties
|
|
7
|
+
};
|
|
7
8
|
|
|
8
9
|
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
9
10
|
for (const k in properties) {
|
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';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
1
|
// The subtree resolver is a higher-level interface that allows you to
|
|
3
2
|
// get the same result that you would from `Swagger.resolve`, but focuses on
|
|
4
3
|
// a subtree of your object.
|
|
@@ -21,7 +20,6 @@ import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
|
21
20
|
// future versions.
|
|
22
21
|
//
|
|
23
22
|
// TODO: move the remarks above into project documentation
|
|
24
|
-
import get from 'lodash/get';
|
|
25
23
|
import resolve from '../resolver/index.js';
|
|
26
24
|
import genericResolverStrategy from '../resolver/strategies/generic/index.js';
|
|
27
25
|
import openApi2ResolverStrategy from '../resolver/strategies/openapi-2/index.js';
|
|
@@ -51,19 +49,23 @@ const resolveSubtree = async function (obj, path) {
|
|
|
51
49
|
};
|
|
52
50
|
const strategy = strategies.find(strg => strg.match(resolveOptions));
|
|
53
51
|
const normalized = strategy.normalize(resolveOptions);
|
|
54
|
-
const result = await resolve(
|
|
52
|
+
const result = await resolve({
|
|
53
|
+
...resolveOptions,
|
|
55
54
|
spec: normalized,
|
|
56
55
|
allowMetaPatches: true,
|
|
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
|
};
|
|
64
63
|
export const makeResolveSubtree = defaultOptions => async function (obj, path) {
|
|
65
64
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
66
|
-
const mergedOptions =
|
|
65
|
+
const mergedOptions = {
|
|
66
|
+
...defaultOptions,
|
|
67
|
+
...options
|
|
68
|
+
};
|
|
67
69
|
return resolveSubtree(obj, path, mergedOptions);
|
|
68
70
|
};
|
|
69
71
|
export default makeResolveSubtree({
|
package/lib/execute/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
5
|
exports.__esModule = true;
|
|
4
6
|
exports.baseUrl = baseUrl;
|
|
5
7
|
exports.buildRequest = buildRequest;
|
|
6
8
|
exports.execute = execute;
|
|
7
9
|
exports.self = void 0;
|
|
8
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
9
|
-
var _url = _interopRequireDefault(require("url"));
|
|
10
10
|
var _cookie = _interopRequireDefault(require("cookie"));
|
|
11
11
|
var _isPlainObject = require("is-plain-object");
|
|
12
|
+
var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
12
13
|
var _index = _interopRequireWildcard(require("../http/index.js"));
|
|
13
14
|
var _createError = _interopRequireDefault(require("../specmap/lib/create-error.js"));
|
|
14
15
|
var _parameterBuilders = _interopRequireDefault(require("./swagger2/parameter-builders.js"));
|
|
@@ -17,18 +18,34 @@ var _buildRequest = _interopRequireDefault(require("./oas3/build-request.js"));
|
|
|
17
18
|
var _buildRequest2 = _interopRequireDefault(require("./swagger2/build-request.js"));
|
|
18
19
|
var _index2 = require("../helpers/index.js");
|
|
19
20
|
var _openapiPredicates = require("../helpers/openapi-predicates.js");
|
|
20
|
-
const _excluded = ["http", "fetch", "spec", "operationId", "pathName", "method", "parameters", "securities"];
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
28
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
29
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
30
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
31
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
|
+
};
|
|
32
49
|
const OperationNotFoundError = (0, _createError.default)('OperationNotFoundError', function cb(message, extra, oriError) {
|
|
33
50
|
this.originalError = oriError;
|
|
34
51
|
Object.assign(this, extra || {});
|
|
@@ -63,30 +80,31 @@ const self = {
|
|
|
63
80
|
exports.self = self;
|
|
64
81
|
function execute(_ref) {
|
|
65
82
|
let {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
http: userHttp,
|
|
84
|
+
fetch,
|
|
85
|
+
// This is legacy
|
|
86
|
+
spec,
|
|
87
|
+
operationId,
|
|
88
|
+
pathName,
|
|
89
|
+
method,
|
|
90
|
+
parameters,
|
|
91
|
+
securities,
|
|
92
|
+
...extras
|
|
93
|
+
} = _ref;
|
|
77
94
|
// Provide default fetch implementation
|
|
78
95
|
const http = userHttp || fetch || _index.default; // Default to _our_ http
|
|
79
96
|
|
|
80
97
|
if (pathName && method && !operationId) {
|
|
81
98
|
operationId = (0, _index2.idFromPathMethodLegacy)(pathName, method);
|
|
82
99
|
}
|
|
83
|
-
const request = self.buildRequest(
|
|
100
|
+
const request = self.buildRequest({
|
|
84
101
|
spec,
|
|
85
102
|
operationId,
|
|
86
103
|
parameters,
|
|
87
104
|
securities,
|
|
88
|
-
http
|
|
89
|
-
|
|
105
|
+
http,
|
|
106
|
+
...extras
|
|
107
|
+
});
|
|
90
108
|
if (request.body && ((0, _isPlainObject.isPlainObject)(request.body) || Array.isArray(request.body))) {
|
|
91
109
|
request.body = JSON.stringify(request.body);
|
|
92
110
|
}
|
|
@@ -233,9 +251,10 @@ function buildRequest(options) {
|
|
|
233
251
|
});
|
|
234
252
|
|
|
235
253
|
// Do version-specific tasks, then return those results.
|
|
236
|
-
const versionSpecificOptions =
|
|
254
|
+
const versionSpecificOptions = {
|
|
255
|
+
...options,
|
|
237
256
|
operation
|
|
238
|
-
}
|
|
257
|
+
};
|
|
239
258
|
if (specIsOAS3) {
|
|
240
259
|
req = (0, _buildRequest.default)(versionSpecificOptions, req);
|
|
241
260
|
} else {
|
|
@@ -273,15 +292,17 @@ function baseUrl(obj) {
|
|
|
273
292
|
const specIsOAS3 = (0, _openapiPredicates.isOpenAPI3)(obj.spec);
|
|
274
293
|
return specIsOAS3 ? oas3BaseUrl(obj) : swagger2BaseUrl(obj);
|
|
275
294
|
}
|
|
276
|
-
function oas3BaseUrl({
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
295
|
+
function oas3BaseUrl(_ref2) {
|
|
296
|
+
var _spec$paths, _spec$paths2;
|
|
297
|
+
let {
|
|
298
|
+
spec,
|
|
299
|
+
pathName,
|
|
300
|
+
method,
|
|
301
|
+
server,
|
|
302
|
+
contextUrl,
|
|
303
|
+
serverVariables = {}
|
|
304
|
+
} = _ref2;
|
|
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);
|
|
285
306
|
let selectedServerUrl = '';
|
|
286
307
|
let selectedServerObj = null;
|
|
287
308
|
if (server && servers && servers.length) {
|
|
@@ -311,13 +332,19 @@ function oas3BaseUrl({
|
|
|
311
332
|
}
|
|
312
333
|
return buildOas3UrlWithContext(selectedServerUrl, contextUrl);
|
|
313
334
|
}
|
|
314
|
-
function buildOas3UrlWithContext(ourUrl
|
|
335
|
+
function buildOas3UrlWithContext(ourUrl, contextUrl) {
|
|
336
|
+
if (ourUrl === void 0) {
|
|
337
|
+
ourUrl = '';
|
|
338
|
+
}
|
|
339
|
+
if (contextUrl === void 0) {
|
|
340
|
+
contextUrl = '';
|
|
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}`;
|
|
@@ -341,12 +368,13 @@ function getVariableTemplateNames(str) {
|
|
|
341
368
|
}
|
|
342
369
|
|
|
343
370
|
// Compose the baseUrl ( scheme + host + basePath )
|
|
344
|
-
function swagger2BaseUrl({
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
371
|
+
function swagger2BaseUrl(_ref3) {
|
|
372
|
+
let {
|
|
373
|
+
spec,
|
|
374
|
+
scheme,
|
|
375
|
+
contextUrl = ''
|
|
376
|
+
} = _ref3;
|
|
377
|
+
const parsedContextUrl = parseURIReference(contextUrl);
|
|
350
378
|
const firstSchemeInSpec = Array.isArray(spec.schemes) ? spec.schemes[0] : null;
|
|
351
379
|
const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http';
|
|
352
380
|
const computedHost = spec.host || parsedContextUrl.host || '';
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.applySecurities = applySecurities;
|
|
5
6
|
exports.default = buildRequest;
|
|
6
7
|
var _isPlainObject = require("is-plain-object");
|
|
7
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
8
8
|
var _btoaNode = _interopRequireDefault(require("../../helpers/btoa.node.js"));
|
|
9
|
-
|
|
10
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // This function runs after the common function,
|
|
9
|
+
// This function runs after the common function,
|
|
15
10
|
// `src/execute/index.js#buildRequest`
|
|
11
|
+
|
|
16
12
|
function buildRequest(options, req) {
|
|
17
13
|
const {
|
|
18
14
|
operation,
|
|
@@ -51,10 +47,14 @@ function buildRequest(options, req) {
|
|
|
51
47
|
req.headers['Content-Type'] = requestContentType;
|
|
52
48
|
}
|
|
53
49
|
if (!options.responseContentType && operation.responses) {
|
|
54
|
-
const mediaTypes = Object.entries(operation.responses).filter(
|
|
50
|
+
const mediaTypes = Object.entries(operation.responses).filter(_ref => {
|
|
51
|
+
let [key, value] = _ref;
|
|
55
52
|
const code = parseInt(key, 10);
|
|
56
53
|
return code >= 200 && code < 300 && (0, _isPlainObject.isPlainObject)(value.content);
|
|
57
|
-
}).reduce((acc,
|
|
54
|
+
}).reduce((acc, _ref2) => {
|
|
55
|
+
let [, value] = _ref2;
|
|
56
|
+
return acc.concat(Object.keys(value.content));
|
|
57
|
+
}, []);
|
|
58
58
|
if (mediaTypes.length > 0) {
|
|
59
59
|
req.headers.accept = mediaTypes.join(', ');
|
|
60
60
|
}
|
|
@@ -69,7 +69,7 @@ function buildRequest(options, req) {
|
|
|
69
69
|
if (requestContentType === 'application/x-www-form-urlencoded' || requestContentType === 'multipart/form-data') {
|
|
70
70
|
if (typeof requestBody === 'object') {
|
|
71
71
|
var _requestBodyDef$conte, _requestBodyDef$conte2;
|
|
72
|
-
const encoding = (_requestBodyDef$conte = (_requestBodyDef$conte2 = requestBodyDef.content[requestContentType])
|
|
72
|
+
const encoding = (_requestBodyDef$conte = (_requestBodyDef$conte2 = requestBodyDef.content[requestContentType]) == null ? void 0 : _requestBodyDef$conte2.encoding) != null ? _requestBodyDef$conte : {};
|
|
73
73
|
req.form = {};
|
|
74
74
|
Object.keys(requestBody).forEach(k => {
|
|
75
75
|
req.form[k] = {
|
|
@@ -93,19 +93,23 @@ function buildRequest(options, req) {
|
|
|
93
93
|
|
|
94
94
|
// Add security values, to operations - that declare their need on them
|
|
95
95
|
// Adapted from the Swagger2 implementation
|
|
96
|
-
function applySecurities({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
function applySecurities(_ref3) {
|
|
97
|
+
var _spec$components;
|
|
98
|
+
let {
|
|
99
|
+
request,
|
|
100
|
+
securities = {},
|
|
101
|
+
operation = {},
|
|
102
|
+
spec
|
|
103
|
+
} = _ref3;
|
|
104
|
+
const result = {
|
|
105
|
+
...request
|
|
106
|
+
};
|
|
103
107
|
const {
|
|
104
108
|
authorized = {}
|
|
105
109
|
} = securities;
|
|
106
110
|
const security = operation.security || spec.security || [];
|
|
107
111
|
const isAuthorized = authorized && !!Object.keys(authorized).length;
|
|
108
|
-
const securityDef = (
|
|
112
|
+
const securityDef = (spec == null || (_spec$components = spec.components) == null ? void 0 : _spec$components.securitySchemes) || {};
|
|
109
113
|
result.headers = result.headers || {};
|
|
110
114
|
result.query = result.query || {};
|
|
111
115
|
if (!Object.keys(securities).length || !isAuthorized || !security || Array.isArray(operation.security) && !operation.security.length) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
3
5
|
exports.__esModule = true;
|
|
4
6
|
exports.cookie = cookie;
|
|
5
7
|
exports.header = header;
|
|
@@ -7,14 +9,12 @@ exports.path = path;
|
|
|
7
9
|
exports.query = query;
|
|
8
10
|
var _styleSerializer = _interopRequireWildcard(require("./style-serializer.js"));
|
|
9
11
|
var _contentSerializer = _interopRequireDefault(require("./content-serializer.js"));
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
parameter
|
|
17
|
-
}) {
|
|
12
|
+
function path(_ref) {
|
|
13
|
+
let {
|
|
14
|
+
req,
|
|
15
|
+
value,
|
|
16
|
+
parameter
|
|
17
|
+
} = _ref;
|
|
18
18
|
const {
|
|
19
19
|
name,
|
|
20
20
|
style,
|
|
@@ -37,11 +37,12 @@ function path({
|
|
|
37
37
|
});
|
|
38
38
|
req.url = req.url.split(`{${name}}`).join(styledValue);
|
|
39
39
|
}
|
|
40
|
-
function query({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
function query(_ref2) {
|
|
41
|
+
let {
|
|
42
|
+
req,
|
|
43
|
+
value,
|
|
44
|
+
parameter
|
|
45
|
+
} = _ref2;
|
|
45
46
|
req.query = req.query || {};
|
|
46
47
|
if (parameter.content) {
|
|
47
48
|
const effectiveMediaType = Object.keys(parameter.content)[0];
|
|
@@ -82,11 +83,12 @@ function query({
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
const PARAMETER_HEADER_BLACKLIST = ['accept', 'authorization', 'content-type'];
|
|
85
|
-
function header({
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
function header(_ref3) {
|
|
87
|
+
let {
|
|
88
|
+
req,
|
|
89
|
+
parameter,
|
|
90
|
+
value
|
|
91
|
+
} = _ref3;
|
|
90
92
|
req.headers = req.headers || {};
|
|
91
93
|
if (PARAMETER_HEADER_BLACKLIST.indexOf(parameter.name.toLowerCase()) > -1) {
|
|
92
94
|
return;
|
|
@@ -106,11 +108,12 @@ function header({
|
|
|
106
108
|
});
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
|
-
function cookie({
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
function cookie(_ref4) {
|
|
112
|
+
let {
|
|
113
|
+
req,
|
|
114
|
+
parameter,
|
|
115
|
+
value
|
|
116
|
+
} = _ref4;
|
|
114
117
|
req.headers = req.headers || {};
|
|
115
118
|
const type = typeof value;
|
|
116
119
|
if (parameter.content) {
|