swagger-client 3.27.2 → 3.27.3
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/dist/swagger-client.browser.js +10806 -11998
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/index.js +5 -8
- package/es/execute/oas3/build-request.js +22 -1
- package/es/http/index.js +6 -382
- package/es/http/serializers/request/file.js +46 -0
- package/es/http/serializers/request/format.js +143 -0
- package/es/http/serializers/request/index.js +111 -0
- package/es/http/serializers/response/index.js +55 -0
- package/es/index.js +2 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/SchemaRefError.js +3 -0
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +5 -4
- package/es/{specmap → resolver/specmap}/helpers.js +1 -1
- package/es/{specmap → resolver/specmap}/lib/refs.js +8 -8
- package/es/resolver/strategies/generic/index.js +1 -1
- package/es/resolver/strategies/generic/resolve.js +1 -1
- package/lib/execute/index.js +8 -11
- package/lib/execute/oas3/build-request.js +22 -1
- package/lib/http/index.js +6 -391
- package/lib/http/serializers/request/file.js +53 -0
- package/lib/http/serializers/request/format.js +147 -0
- package/lib/http/serializers/request/index.js +117 -0
- package/lib/http/serializers/response/index.js +63 -0
- package/lib/index.js +34 -33
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/SchemaRefError.js +7 -0
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +6 -5
- package/lib/{specmap → resolver/specmap}/helpers.js +1 -1
- package/lib/{specmap → resolver/specmap}/lib/refs.js +8 -8
- package/lib/resolver/strategies/generic/index.js +1 -1
- package/lib/resolver/strategies/generic/resolve.js +1 -1
- package/package.json +1 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +0 -7
- package/es/specmap/lib/create-error.js +0 -17
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +0 -11
- package/lib/specmap/lib/create-error.js +0 -21
- /package/es/{specmap → resolver/specmap}/index.js +0 -0
- /package/es/{specmap → resolver/specmap}/lib/all-of.js +0 -0
- /package/es/{specmap → resolver/specmap}/lib/context-tree.js +0 -0
- /package/es/{specmap → resolver/specmap}/lib/index.js +0 -0
- /package/es/{specmap → resolver/specmap}/lib/parameters.js +0 -0
- /package/es/{specmap → resolver/specmap}/lib/properties.js +0 -0
- /package/lib/{specmap → resolver/specmap}/index.js +0 -0
- /package/lib/{specmap → resolver/specmap}/lib/all-of.js +0 -0
- /package/lib/{specmap → resolver/specmap}/lib/context-tree.js +0 -0
- /package/lib/{specmap → resolver/specmap}/lib/index.js +0 -0
- /package/lib/{specmap → resolver/specmap}/lib/parameters.js +0 -0
- /package/lib/{specmap → resolver/specmap}/lib/properties.js +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import qs from 'qs';
|
|
2
|
+
import formatKeyValue from './format.js';
|
|
3
|
+
import { isFile, isArrayOfFile, FileWithData } from './file.js';
|
|
4
|
+
function buildFormData(reqForm) {
|
|
5
|
+
/**
|
|
6
|
+
* Build a new FormData instance, support array as field value
|
|
7
|
+
* OAS2.0 - when collectionFormat is multi
|
|
8
|
+
* OAS3.0 - when explode of Encoding Object is true
|
|
9
|
+
*
|
|
10
|
+
* This function explicitly handles Buffers (for backward compatibility)
|
|
11
|
+
* if provided as a values to FormData. FormData can only handle USVString
|
|
12
|
+
* or Blob.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} reqForm - ori req.form
|
|
15
|
+
* @return {FormData} - new FormData instance
|
|
16
|
+
*/
|
|
17
|
+
return Object.entries(reqForm).reduce((formData, [name, input]) => {
|
|
18
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
19
|
+
for (const [key, value] of formatKeyValue(name, input, true)) {
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
22
|
+
for (const v of value) {
|
|
23
|
+
if (ArrayBuffer.isView(v)) {
|
|
24
|
+
const blob = new Blob([v]);
|
|
25
|
+
formData.append(key, blob);
|
|
26
|
+
} else {
|
|
27
|
+
formData.append(key, v);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
31
|
+
const blob = new Blob([value]);
|
|
32
|
+
formData.append(key, blob);
|
|
33
|
+
} else {
|
|
34
|
+
formData.append(key, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return formData;
|
|
38
|
+
}, new FormData());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Encodes an object using appropriate serializer.
|
|
42
|
+
export function encodeFormOrQuery(data) {
|
|
43
|
+
/**
|
|
44
|
+
* Encode parameter names and values
|
|
45
|
+
* @param {Object} result - parameter names and values
|
|
46
|
+
* @param {string} parameterName - Parameter name
|
|
47
|
+
* @return {object} encoded parameter names and values
|
|
48
|
+
*/
|
|
49
|
+
const encodedQuery = Object.keys(data).reduce((result, parameterName) => {
|
|
50
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
51
|
+
for (const [key, value] of formatKeyValue(parameterName, data[parameterName])) {
|
|
52
|
+
if (value instanceof FileWithData) {
|
|
53
|
+
result[key] = value.valueOf();
|
|
54
|
+
} else {
|
|
55
|
+
result[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}, {});
|
|
60
|
+
return qs.stringify(encodedQuery, {
|
|
61
|
+
encode: false,
|
|
62
|
+
indices: false
|
|
63
|
+
}) || '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If the request has a `query` object, merge it into the request.url, and delete the object
|
|
67
|
+
// If file and/or multipart, also create FormData instance
|
|
68
|
+
export function serializeRequest(req = {}) {
|
|
69
|
+
const {
|
|
70
|
+
url = '',
|
|
71
|
+
query,
|
|
72
|
+
form
|
|
73
|
+
} = req;
|
|
74
|
+
const joinSearch = (...strs) => {
|
|
75
|
+
const search = strs.filter(a => a).join('&'); // Only truthy value
|
|
76
|
+
return search ? `?${search}` : ''; // Only add '?' if there is a str
|
|
77
|
+
};
|
|
78
|
+
if (form) {
|
|
79
|
+
const hasFile = Object.keys(form).some(key => {
|
|
80
|
+
const {
|
|
81
|
+
value
|
|
82
|
+
} = form[key];
|
|
83
|
+
return isFile(value) || isArrayOfFile(value);
|
|
84
|
+
});
|
|
85
|
+
const contentType = req.headers['content-type'] || req.headers['Content-Type'];
|
|
86
|
+
if (hasFile || /multipart\/form-data/i.test(contentType)) {
|
|
87
|
+
const formdata = buildFormData(req.form);
|
|
88
|
+
req.formdata = formdata;
|
|
89
|
+
req.body = formdata;
|
|
90
|
+
} else {
|
|
91
|
+
req.body = encodeFormOrQuery(form);
|
|
92
|
+
}
|
|
93
|
+
delete req.form;
|
|
94
|
+
}
|
|
95
|
+
if (query) {
|
|
96
|
+
const [baseUrl, oriSearch] = url.split('?');
|
|
97
|
+
let newStr = '';
|
|
98
|
+
if (oriSearch) {
|
|
99
|
+
const oriQuery = qs.parse(oriSearch);
|
|
100
|
+
const keysToRemove = Object.keys(query);
|
|
101
|
+
keysToRemove.forEach(key => delete oriQuery[key]);
|
|
102
|
+
newStr = qs.stringify(oriQuery, {
|
|
103
|
+
encode: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const finalStr = joinSearch(newStr, encodeFormOrQuery(query));
|
|
107
|
+
req.url = baseUrl + finalStr;
|
|
108
|
+
delete req.query;
|
|
109
|
+
}
|
|
110
|
+
return req;
|
|
111
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import jsYaml from 'js-yaml';
|
|
2
|
+
export const shouldDownloadAsText = (contentType = '') => /(json|xml|yaml|text)\b/.test(contentType);
|
|
3
|
+
function parseBody(body, contentType) {
|
|
4
|
+
if (contentType && (contentType.indexOf('application/json') === 0 || contentType.indexOf('+json') > 0)) {
|
|
5
|
+
return JSON.parse(body);
|
|
6
|
+
}
|
|
7
|
+
return jsYaml.load(body);
|
|
8
|
+
}
|
|
9
|
+
function serializeHeaderValue(value) {
|
|
10
|
+
const isMulti = value.includes(', ');
|
|
11
|
+
return isMulti ? value.split(', ') : value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Serialize headers into a hash, where mutliple-headers result in an array.
|
|
15
|
+
//
|
|
16
|
+
// eg: Cookie: one
|
|
17
|
+
// Cookie: two
|
|
18
|
+
// = { Cookie: [ "one", "two" ]
|
|
19
|
+
export function serializeHeaders(headers = {}) {
|
|
20
|
+
if (typeof headers.entries !== 'function') return {};
|
|
21
|
+
return Array.from(headers.entries()).reduce((acc, [header, value]) => {
|
|
22
|
+
acc[header] = serializeHeaderValue(value);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Serialize the response, returns a promise with headers and the body part of the hash
|
|
28
|
+
export function serializeResponse(oriRes, url, {
|
|
29
|
+
loadSpec = false
|
|
30
|
+
} = {}) {
|
|
31
|
+
const res = {
|
|
32
|
+
ok: oriRes.ok,
|
|
33
|
+
url: oriRes.url || url,
|
|
34
|
+
status: oriRes.status,
|
|
35
|
+
statusText: oriRes.statusText,
|
|
36
|
+
headers: serializeHeaders(oriRes.headers)
|
|
37
|
+
};
|
|
38
|
+
const contentType = res.headers['content-type'];
|
|
39
|
+
const useText = loadSpec || shouldDownloadAsText(contentType);
|
|
40
|
+
const getBody = useText ? oriRes.text : oriRes.blob || oriRes.buffer;
|
|
41
|
+
return getBody.call(oriRes).then(body => {
|
|
42
|
+
res.text = body;
|
|
43
|
+
res.data = body;
|
|
44
|
+
if (useText) {
|
|
45
|
+
try {
|
|
46
|
+
const obj = parseBody(body, contentType);
|
|
47
|
+
res.body = obj;
|
|
48
|
+
res.obj = obj;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
res.parseError = e;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
});
|
|
55
|
+
}
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
2
|
import { DEFAULT_OPENAPI_3_SERVER } from './constants.js';
|
|
3
|
-
import Http, { makeHttp, serializeRes
|
|
3
|
+
import Http, { makeHttp, serializeRes } from './http/index.js';
|
|
4
|
+
import { serializeHeaders } from './http/serializers/response/index.js';
|
|
4
5
|
import { makeResolve } from './resolver/index.js';
|
|
5
6
|
import { makeResolveSubtree } from './subtree-resolver/index.js';
|
|
6
7
|
import genericResolveStrategy from './resolver/strategies/generic/index.js';
|
|
@@ -9,8 +9,8 @@ import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from '@swagger-api
|
|
|
9
9
|
import { evaluate as uriEvaluate, EvaluationJsonSchemaUriError } from '@swagger-api/apidom-reference/dereference/strategies/openapi-3-1/selectors/uri';
|
|
10
10
|
import toPath from '../utils/to-path.js';
|
|
11
11
|
import getRootCause from '../utils/get-root-cause.js';
|
|
12
|
-
import specMapMod from '
|
|
13
|
-
import
|
|
12
|
+
import specMapMod from '../../../../../../specmap/lib/refs.js';
|
|
13
|
+
import SchemaRefError from '../errors/SchemaRefError.js';
|
|
14
14
|
const {
|
|
15
15
|
wrapError
|
|
16
16
|
} = specMapMod;
|
|
@@ -660,8 +660,9 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
|
|
|
660
660
|
const wrappedError = new SchemaRefError(`Could not resolve reference: ${rootCause.message}`, {
|
|
661
661
|
baseDoc: this.reference.uri,
|
|
662
662
|
$ref: toValue(referencingElement.$ref),
|
|
663
|
-
fullPath: (_this$basePath6 = this.basePath) !== null && _this$basePath6 !== void 0 ? _this$basePath6 : [...toPath([...ancestors, parent, referencingElement]), '$ref']
|
|
664
|
-
|
|
663
|
+
fullPath: (_this$basePath6 = this.basePath) !== null && _this$basePath6 !== void 0 ? _this$basePath6 : [...toPath([...ancestors, parent, referencingElement]), '$ref'],
|
|
664
|
+
cause: rootCause
|
|
665
|
+
});
|
|
665
666
|
(_this$options$derefer11 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer11 === void 0 || (_this$options$derefer11 = _this$options$derefer11.errors) === null || _this$options$derefer11 === void 0 || (_this$options$derefer12 = _this$options$derefer11.push) === null || _this$options$derefer12 === void 0 || _this$options$derefer12.call(_this$options$derefer11, wrappedError);
|
|
666
667
|
return undefined;
|
|
667
668
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import traverse from 'traverse';
|
|
2
2
|
import { url } from '@swagger-api/apidom-reference/configuration/empty';
|
|
3
|
-
import { DEFAULT_BASE_URL } from '
|
|
3
|
+
import { DEFAULT_BASE_URL } from '../../constants.js';
|
|
4
4
|
|
|
5
5
|
// This will match if the direct parent's key exactly matches an item.
|
|
6
6
|
const freelyNamedKeyParents = ['properties'];
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import jsYaml from 'js-yaml';
|
|
2
|
+
import { ApiDOMStructuredError } from '@swagger-api/apidom-error';
|
|
2
3
|
import { url } from '@swagger-api/apidom-reference/configuration/empty';
|
|
3
|
-
import '
|
|
4
|
+
import '../../../helpers/fetch-polyfill.node.js';
|
|
4
5
|
import lib from './index.js';
|
|
5
|
-
import createError from './create-error.js';
|
|
6
6
|
import { isFreelyNamed, absolutifyPointer } from '../helpers.js';
|
|
7
|
-
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from '
|
|
7
|
+
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from '../../../constants.js';
|
|
8
8
|
const ABSOLUTE_URL_REGEXP = /^([a-z]+:\/\/|\/\/)/i;
|
|
9
|
-
|
|
10
|
-
this.originalError = oriError;
|
|
11
|
-
Object.assign(this, extra || {});
|
|
12
|
-
});
|
|
9
|
+
class JSONRefError extends ApiDOMStructuredError {}
|
|
13
10
|
const docCache = {};
|
|
14
11
|
const specmapRefs = new WeakMap();
|
|
15
12
|
const skipResolutionTestFns = [
|
|
@@ -228,7 +225,10 @@ function wrapError(e, extra) {
|
|
|
228
225
|
} else {
|
|
229
226
|
message = e.message;
|
|
230
227
|
}
|
|
231
|
-
return new JSONRefError(`Could not resolve reference: ${message}`,
|
|
228
|
+
return new JSONRefError(`Could not resolve reference: ${message}`, {
|
|
229
|
+
...extra,
|
|
230
|
+
cause: e
|
|
231
|
+
});
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mapSpec, { plugins } from '
|
|
1
|
+
import mapSpec, { plugins } from '../../specmap/index.js';
|
|
2
2
|
import normalize from './normalize.js';
|
|
3
3
|
import { makeFetchJSON } from '../../utils/index.js';
|
|
4
4
|
import * as optionsUtil from '../../utils/options.js';
|
package/lib/execute/index.js
CHANGED
|
@@ -9,15 +9,16 @@ exports.execute = execute;
|
|
|
9
9
|
exports.self = void 0;
|
|
10
10
|
var _cookie = _interopRequireDefault(require("cookie"));
|
|
11
11
|
var _isPlainObject = require("is-plain-object");
|
|
12
|
+
var _apidomError = require("@swagger-api/apidom-error");
|
|
12
13
|
var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
13
14
|
var _constants = require("../constants.js");
|
|
14
|
-
var _index =
|
|
15
|
-
var
|
|
15
|
+
var _index = _interopRequireDefault(require("../http/index.js"));
|
|
16
|
+
var _index2 = require("../http/serializers/request/index.js");
|
|
16
17
|
var _parameterBuilders = _interopRequireDefault(require("./swagger2/parameter-builders.js"));
|
|
17
18
|
var OAS3_PARAMETER_BUILDERS = _interopRequireWildcard(require("./oas3/parameter-builders.js"));
|
|
18
19
|
var _buildRequest = _interopRequireDefault(require("./oas3/build-request.js"));
|
|
19
20
|
var _buildRequest2 = _interopRequireDefault(require("./swagger2/build-request.js"));
|
|
20
|
-
var
|
|
21
|
+
var _index3 = require("../helpers/index.js");
|
|
21
22
|
var _openapiPredicates = require("../helpers/openapi-predicates.js");
|
|
22
23
|
const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
|
|
23
24
|
|
|
@@ -47,10 +48,7 @@ const parseURIReference = uriReference => {
|
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
|
-
|
|
51
|
-
this.originalError = oriError;
|
|
52
|
-
Object.assign(this, extra || {});
|
|
53
|
-
});
|
|
51
|
+
class OperationNotFoundError extends _apidomError.ApiDOMStructuredError {}
|
|
54
52
|
const findParametersWithName = (name, parameters) => parameters.filter(p => p.name === name);
|
|
55
53
|
|
|
56
54
|
// removes parameters that have duplicate 'in' and 'name' properties
|
|
@@ -94,7 +92,7 @@ function execute({
|
|
|
94
92
|
const http = userHttp || fetch || _index.default; // Default to _our_ http
|
|
95
93
|
|
|
96
94
|
if (pathName && method && !operationId) {
|
|
97
|
-
operationId = (0,
|
|
95
|
+
operationId = (0, _index3.idFromPathMethodLegacy)(pathName, method);
|
|
98
96
|
}
|
|
99
97
|
const request = self.buildRequest({
|
|
100
98
|
spec,
|
|
@@ -164,7 +162,7 @@ function buildRequest(options) {
|
|
|
164
162
|
if (userFetch) {
|
|
165
163
|
req.userFetch = userFetch;
|
|
166
164
|
}
|
|
167
|
-
const operationRaw = (0,
|
|
165
|
+
const operationRaw = (0, _index3.getOperationRaw)(spec, operationId);
|
|
168
166
|
if (!operationRaw) {
|
|
169
167
|
throw new OperationNotFoundError(`Operation ${operationId} not found`);
|
|
170
168
|
}
|
|
@@ -281,8 +279,7 @@ function buildRequest(options) {
|
|
|
281
279
|
|
|
282
280
|
// Will add the query object into the URL, if it exists
|
|
283
281
|
// ... will also create a FormData instance, if multipart/form-data (eg: a file)
|
|
284
|
-
(0,
|
|
285
|
-
return req;
|
|
282
|
+
return (0, _index2.serializeRequest)(req);
|
|
286
283
|
}
|
|
287
284
|
const stripNonAlpha = str => str ? str.replace(/\W/g, '') : null;
|
|
288
285
|
|
|
@@ -68,11 +68,32 @@ function buildRequest(options, req) {
|
|
|
68
68
|
const encoding = (_requestBodyDef$conte = (_requestBodyDef$conte2 = requestBodyDef.content[requestContentType]) == null ? void 0 : _requestBodyDef$conte2.encoding) != null ? _requestBodyDef$conte : {};
|
|
69
69
|
req.form = {};
|
|
70
70
|
Object.keys(requestBody).forEach(k => {
|
|
71
|
+
let value;
|
|
72
|
+
try {
|
|
73
|
+
value = JSON.parse(requestBody[k]);
|
|
74
|
+
} catch {
|
|
75
|
+
value = requestBody[k];
|
|
76
|
+
}
|
|
71
77
|
req.form[k] = {
|
|
72
|
-
value
|
|
78
|
+
value,
|
|
73
79
|
encoding: encoding[k] || {}
|
|
74
80
|
};
|
|
75
81
|
});
|
|
82
|
+
} else if (typeof requestBody === 'string') {
|
|
83
|
+
var _requestBodyDef$conte3, _requestBodyDef$conte4;
|
|
84
|
+
const encoding = (_requestBodyDef$conte3 = (_requestBodyDef$conte4 = requestBodyDef.content[requestContentType]) == null ? void 0 : _requestBodyDef$conte4.encoding) != null ? _requestBodyDef$conte3 : {};
|
|
85
|
+
try {
|
|
86
|
+
req.form = {};
|
|
87
|
+
const form = JSON.parse(requestBody);
|
|
88
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
89
|
+
req.form[key] = {
|
|
90
|
+
value,
|
|
91
|
+
encoding: encoding[key] || {}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
} catch {
|
|
95
|
+
req.form = requestBody;
|
|
96
|
+
}
|
|
76
97
|
} else {
|
|
77
98
|
req.form = requestBody;
|
|
78
99
|
}
|