swagger-client 3.10.8 → 3.10.12
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 +10 -2
- package/dist/swagger-client.browser.js +24191 -0
- package/dist/swagger-client.browser.min.js +3 -0
- package/dist/swagger-client.browser.min.js.map +1 -0
- package/es/commonjs.js +9 -0
- package/es/constants.js +2 -0
- package/es/execute/index.js +391 -0
- package/es/execute/oas3/build-request.js +149 -0
- package/es/execute/oas3/content-serializer.js +18 -0
- package/es/execute/oas3/parameter-builders.js +119 -0
- package/es/execute/oas3/style-serializer.js +232 -0
- package/es/execute/swagger2/build-request.js +119 -0
- package/es/execute/swagger2/parameter-builders.js +78 -0
- package/es/helpers.js +272 -0
- package/es/http.js +621 -0
- package/es/index.js +116 -0
- package/es/interfaces.js +145 -0
- package/es/internal/form-data-monkey-patch.js +94 -0
- package/es/resolver.js +123 -0
- package/es/specmap/helpers.js +62 -0
- package/es/specmap/index.js +613 -0
- package/es/specmap/lib/all-of.js +81 -0
- package/es/specmap/lib/context-tree.js +111 -0
- package/es/specmap/lib/create-error.js +24 -0
- package/es/specmap/lib/index.js +391 -0
- package/es/specmap/lib/parameters.js +31 -0
- package/es/specmap/lib/properties.js +23 -0
- package/es/specmap/lib/refs.js +516 -0
- package/es/subtree-resolver/index.js +92 -0
- package/lib/commonjs.js +10 -0
- package/lib/constants.js +7 -0
- package/lib/execute/index.js +421 -0
- package/lib/execute/oas3/build-request.js +161 -0
- package/lib/execute/oas3/content-serializer.js +21 -0
- package/lib/execute/oas3/parameter-builders.js +138 -0
- package/lib/execute/oas3/style-serializer.js +208 -0
- package/lib/execute/swagger2/build-request.js +120 -0
- package/lib/execute/swagger2/parameter-builders.js +88 -0
- package/lib/helpers.js +261 -0
- package/lib/http.js +470 -0
- package/lib/index.js +142 -0
- package/lib/interfaces.js +159 -0
- package/lib/internal/form-data-monkey-patch.js +83 -0
- package/lib/resolver.js +125 -0
- package/lib/specmap/helpers.js +65 -0
- package/lib/specmap/index.js +446 -0
- package/lib/specmap/lib/all-of.js +89 -0
- package/lib/specmap/lib/context-tree.js +111 -0
- package/lib/specmap/lib/create-error.js +25 -0
- package/lib/specmap/lib/index.js +402 -0
- package/lib/specmap/lib/parameters.js +42 -0
- package/lib/specmap/lib/properties.js +38 -0
- package/lib/specmap/lib/refs.js +509 -0
- package/lib/subtree-resolver/index.js +55 -0
- package/package.json +80 -106
- package/browser/index.js +0 -54
- package/dist/index.js +0 -4372
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
|
|
2
|
+
import _typeof from "@babel/runtime-corejs2/helpers/typeof";
|
|
3
|
+
import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
|
|
4
|
+
import _toConsumableArray from "@babel/runtime-corejs2/helpers/toConsumableArray";
|
|
5
|
+
|
|
6
|
+
var _require = require('buffer'),
|
|
7
|
+
Buffer = _require.Buffer;
|
|
8
|
+
|
|
9
|
+
var isRfc3986Reserved = function isRfc3986Reserved(char) {
|
|
10
|
+
return ":/?#[]@!$&'()*+,;=".indexOf(char) > -1;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
var isRrc3986Unreserved = function isRrc3986Unreserved(char) {
|
|
14
|
+
return /^[a-z0-9\-._~]+$/i.test(char);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function encodeDisallowedCharacters(str) {
|
|
18
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
19
|
+
escape = _ref.escape;
|
|
20
|
+
|
|
21
|
+
var parse = arguments.length > 2 ? arguments[2] : undefined;
|
|
22
|
+
|
|
23
|
+
if (typeof str === 'number') {
|
|
24
|
+
str = str.toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof str !== 'string' || !str.length) {
|
|
28
|
+
return str;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!escape) {
|
|
32
|
+
return str;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (parse) {
|
|
36
|
+
return JSON.parse(str);
|
|
37
|
+
} // In ES6 you can do this quite easily by using the new ... spread operator.
|
|
38
|
+
// This causes the string iterator (another new ES6 feature) to be used internally,
|
|
39
|
+
// and because that iterator is designed to deal with
|
|
40
|
+
// code points rather than UCS-2/UTF-16 code units.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
return _toConsumableArray(str).map(function (char) {
|
|
44
|
+
if (isRrc3986Unreserved(char)) {
|
|
45
|
+
return char;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isRfc3986Reserved(char) && escape === 'unsafe') {
|
|
49
|
+
return char;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var encoded = (Buffer.from(char).toJSON().data || []).map(function (byte) {
|
|
53
|
+
return "0".concat(byte.toString(16).toUpperCase()).slice(-2);
|
|
54
|
+
}).map(function (encodedByte) {
|
|
55
|
+
return "%".concat(encodedByte);
|
|
56
|
+
}).join('');
|
|
57
|
+
return encoded;
|
|
58
|
+
}).join('');
|
|
59
|
+
}
|
|
60
|
+
export default function stylize(config) {
|
|
61
|
+
var value = config.value;
|
|
62
|
+
|
|
63
|
+
if (_Array$isArray(value)) {
|
|
64
|
+
return encodeArray(config);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (_typeof(value) === 'object') {
|
|
68
|
+
return encodeObject(config);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return encodePrimitive(config);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function encodeArray(_ref2) {
|
|
75
|
+
var key = _ref2.key,
|
|
76
|
+
value = _ref2.value,
|
|
77
|
+
style = _ref2.style,
|
|
78
|
+
explode = _ref2.explode,
|
|
79
|
+
escape = _ref2.escape;
|
|
80
|
+
|
|
81
|
+
var valueEncoder = function valueEncoder(str) {
|
|
82
|
+
return encodeDisallowedCharacters(str, {
|
|
83
|
+
escape: escape
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (style === 'simple') {
|
|
88
|
+
return value.map(function (val) {
|
|
89
|
+
return valueEncoder(val);
|
|
90
|
+
}).join(',');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (style === 'label') {
|
|
94
|
+
return ".".concat(value.map(function (val) {
|
|
95
|
+
return valueEncoder(val);
|
|
96
|
+
}).join('.'));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (style === 'matrix') {
|
|
100
|
+
return value.map(function (val) {
|
|
101
|
+
return valueEncoder(val);
|
|
102
|
+
}).reduce(function (prev, curr) {
|
|
103
|
+
if (!prev || explode) {
|
|
104
|
+
return "".concat(prev || '', ";").concat(key, "=").concat(curr);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return "".concat(prev, ",").concat(curr);
|
|
108
|
+
}, '');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (style === 'form') {
|
|
112
|
+
var after = explode ? "&".concat(key, "=") : ',';
|
|
113
|
+
return value.map(function (val) {
|
|
114
|
+
return valueEncoder(val);
|
|
115
|
+
}).join(after);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (style === 'spaceDelimited') {
|
|
119
|
+
var _after = explode ? "".concat(key, "=") : '';
|
|
120
|
+
|
|
121
|
+
return value.map(function (val) {
|
|
122
|
+
return valueEncoder(val);
|
|
123
|
+
}).join(" ".concat(_after));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (style === 'pipeDelimited') {
|
|
127
|
+
var _after2 = explode ? "".concat(key, "=") : '';
|
|
128
|
+
|
|
129
|
+
return value.map(function (val) {
|
|
130
|
+
return valueEncoder(val);
|
|
131
|
+
}).join("|".concat(_after2));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function encodeObject(_ref3) {
|
|
138
|
+
var key = _ref3.key,
|
|
139
|
+
value = _ref3.value,
|
|
140
|
+
style = _ref3.style,
|
|
141
|
+
explode = _ref3.explode,
|
|
142
|
+
escape = _ref3.escape;
|
|
143
|
+
|
|
144
|
+
var valueEncoder = function valueEncoder(str) {
|
|
145
|
+
return encodeDisallowedCharacters(str, {
|
|
146
|
+
escape: escape
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var valueKeys = _Object$keys(value);
|
|
151
|
+
|
|
152
|
+
if (style === 'simple') {
|
|
153
|
+
return valueKeys.reduce(function (prev, curr) {
|
|
154
|
+
var val = valueEncoder(value[curr]);
|
|
155
|
+
var middleChar = explode ? '=' : ',';
|
|
156
|
+
var prefix = prev ? "".concat(prev, ",") : '';
|
|
157
|
+
return "".concat(prefix).concat(curr).concat(middleChar).concat(val);
|
|
158
|
+
}, '');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (style === 'label') {
|
|
162
|
+
return valueKeys.reduce(function (prev, curr) {
|
|
163
|
+
var val = valueEncoder(value[curr]);
|
|
164
|
+
var middleChar = explode ? '=' : '.';
|
|
165
|
+
var prefix = prev ? "".concat(prev, ".") : '.';
|
|
166
|
+
return "".concat(prefix).concat(curr).concat(middleChar).concat(val);
|
|
167
|
+
}, '');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (style === 'matrix' && explode) {
|
|
171
|
+
return valueKeys.reduce(function (prev, curr) {
|
|
172
|
+
var val = valueEncoder(value[curr]);
|
|
173
|
+
var prefix = prev ? "".concat(prev, ";") : ';';
|
|
174
|
+
return "".concat(prefix).concat(curr, "=").concat(val);
|
|
175
|
+
}, '');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (style === 'matrix') {
|
|
179
|
+
// no explode
|
|
180
|
+
return valueKeys.reduce(function (prev, curr) {
|
|
181
|
+
var val = valueEncoder(value[curr]);
|
|
182
|
+
var prefix = prev ? "".concat(prev, ",") : ";".concat(key, "=");
|
|
183
|
+
return "".concat(prefix).concat(curr, ",").concat(val);
|
|
184
|
+
}, '');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (style === 'form') {
|
|
188
|
+
return valueKeys.reduce(function (prev, curr) {
|
|
189
|
+
var val = valueEncoder(value[curr]);
|
|
190
|
+
var prefix = prev ? "".concat(prev).concat(explode ? '&' : ',') : '';
|
|
191
|
+
var separator = explode ? '=' : ',';
|
|
192
|
+
return "".concat(prefix).concat(curr).concat(separator).concat(val);
|
|
193
|
+
}, '');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function encodePrimitive(_ref4) {
|
|
200
|
+
var key = _ref4.key,
|
|
201
|
+
value = _ref4.value,
|
|
202
|
+
style = _ref4.style,
|
|
203
|
+
escape = _ref4.escape;
|
|
204
|
+
|
|
205
|
+
var valueEncoder = function valueEncoder(str) {
|
|
206
|
+
return encodeDisallowedCharacters(str, {
|
|
207
|
+
escape: escape
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (style === 'simple') {
|
|
212
|
+
return valueEncoder(value);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (style === 'label') {
|
|
216
|
+
return ".".concat(valueEncoder(value));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (style === 'matrix') {
|
|
220
|
+
return ";".concat(key, "=").concat(valueEncoder(value));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (style === 'form') {
|
|
224
|
+
return valueEncoder(value);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (style === 'deepObject') {
|
|
228
|
+
return valueEncoder(value, {}, true);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
|
|
2
|
+
import _slicedToArray from "@babel/runtime-corejs2/helpers/slicedToArray";
|
|
3
|
+
import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
|
|
4
|
+
import btoa from 'btoa';
|
|
5
|
+
import assign from 'lodash/assign'; // This function runs after the common function,
|
|
6
|
+
// `src/execute/index.js#buildRequest`
|
|
7
|
+
|
|
8
|
+
export default function buildRequest(options, req) {
|
|
9
|
+
var spec = options.spec,
|
|
10
|
+
operation = options.operation,
|
|
11
|
+
securities = options.securities,
|
|
12
|
+
requestContentType = options.requestContentType,
|
|
13
|
+
attachContentTypeForEmptyPayload = options.attachContentTypeForEmptyPayload; // Add securities, which are applicable
|
|
14
|
+
|
|
15
|
+
req = applySecurities({
|
|
16
|
+
request: req,
|
|
17
|
+
securities: securities,
|
|
18
|
+
operation: operation,
|
|
19
|
+
spec: spec
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (req.body || req.form || attachContentTypeForEmptyPayload) {
|
|
23
|
+
// all following conditionals are Swagger2 only
|
|
24
|
+
if (requestContentType) {
|
|
25
|
+
req.headers['Content-Type'] = requestContentType;
|
|
26
|
+
} else if (_Array$isArray(operation.consumes)) {
|
|
27
|
+
var _operation$consumes = _slicedToArray(operation.consumes, 1);
|
|
28
|
+
|
|
29
|
+
req.headers['Content-Type'] = _operation$consumes[0];
|
|
30
|
+
} else if (_Array$isArray(spec.consumes)) {
|
|
31
|
+
var _spec$consumes = _slicedToArray(spec.consumes, 1);
|
|
32
|
+
|
|
33
|
+
req.headers['Content-Type'] = _spec$consumes[0];
|
|
34
|
+
} else if (operation.parameters && operation.parameters.filter(function (p) {
|
|
35
|
+
return p.type === 'file';
|
|
36
|
+
}).length) {
|
|
37
|
+
req.headers['Content-Type'] = 'multipart/form-data';
|
|
38
|
+
} else if (operation.parameters && operation.parameters.filter(function (p) {
|
|
39
|
+
return p.in === 'formData';
|
|
40
|
+
}).length) {
|
|
41
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
42
|
+
}
|
|
43
|
+
} else if (requestContentType) {
|
|
44
|
+
var isBodyParamPresent = operation.parameters && operation.parameters.filter(function (p) {
|
|
45
|
+
return p.in === 'body';
|
|
46
|
+
}).length > 0;
|
|
47
|
+
var isFormDataParamPresent = operation.parameters && operation.parameters.filter(function (p) {
|
|
48
|
+
return p.in === 'formData';
|
|
49
|
+
}).length > 0;
|
|
50
|
+
|
|
51
|
+
if (isBodyParamPresent || isFormDataParamPresent) {
|
|
52
|
+
req.headers['Content-Type'] = requestContentType;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return req;
|
|
57
|
+
} // Add security values, to operations - that declare their need on them
|
|
58
|
+
|
|
59
|
+
export function applySecurities(_ref) {
|
|
60
|
+
var request = _ref.request,
|
|
61
|
+
_ref$securities = _ref.securities,
|
|
62
|
+
securities = _ref$securities === void 0 ? {} : _ref$securities,
|
|
63
|
+
_ref$operation = _ref.operation,
|
|
64
|
+
operation = _ref$operation === void 0 ? {} : _ref$operation,
|
|
65
|
+
spec = _ref.spec;
|
|
66
|
+
var result = assign({}, request);
|
|
67
|
+
var _securities$authorize = securities.authorized,
|
|
68
|
+
authorized = _securities$authorize === void 0 ? {} : _securities$authorize,
|
|
69
|
+
_securities$specSecur = securities.specSecurity,
|
|
70
|
+
specSecurity = _securities$specSecur === void 0 ? [] : _securities$specSecur;
|
|
71
|
+
var security = operation.security || specSecurity;
|
|
72
|
+
var isAuthorized = authorized && !!_Object$keys(authorized).length;
|
|
73
|
+
var securityDef = spec.securityDefinitions;
|
|
74
|
+
result.headers = result.headers || {};
|
|
75
|
+
result.query = result.query || {};
|
|
76
|
+
|
|
77
|
+
if (!_Object$keys(securities).length || !isAuthorized || !security || _Array$isArray(operation.security) && !operation.security.length) {
|
|
78
|
+
return request;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
security.forEach(function (securityObj) {
|
|
82
|
+
_Object$keys(securityObj).forEach(function (key) {
|
|
83
|
+
var auth = authorized[key];
|
|
84
|
+
|
|
85
|
+
if (!auth) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var token = auth.token;
|
|
90
|
+
var value = auth.value || auth;
|
|
91
|
+
var schema = securityDef[key];
|
|
92
|
+
var type = schema.type;
|
|
93
|
+
var tokenName = schema['x-tokenName'] || 'access_token';
|
|
94
|
+
var oauthToken = token && token[tokenName];
|
|
95
|
+
var tokenType = token && token.token_type;
|
|
96
|
+
|
|
97
|
+
if (auth) {
|
|
98
|
+
if (type === 'apiKey') {
|
|
99
|
+
var inType = schema.in === 'query' ? 'query' : 'headers';
|
|
100
|
+
result[inType] = result[inType] || {};
|
|
101
|
+
result[inType][schema.name] = value;
|
|
102
|
+
} else if (type === 'basic') {
|
|
103
|
+
if (value.header) {
|
|
104
|
+
result.headers.authorization = value.header;
|
|
105
|
+
} else {
|
|
106
|
+
var username = value.username || '';
|
|
107
|
+
var password = value.password || '';
|
|
108
|
+
value.base64 = btoa("".concat(username, ":").concat(password));
|
|
109
|
+
result.headers.authorization = "Basic ".concat(value.base64);
|
|
110
|
+
}
|
|
111
|
+
} else if (type === 'oauth2' && oauthToken) {
|
|
112
|
+
tokenType = !tokenType || tokenType.toLowerCase() === 'bearer' ? 'Bearer' : tokenType;
|
|
113
|
+
result.headers.authorization = "".concat(tokenType, " ").concat(oauthToken);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// These functions will update the request.
|
|
2
|
+
// They'll be given {req, value, paramter, spec, operation}.
|
|
3
|
+
export default {
|
|
4
|
+
body: bodyBuilder,
|
|
5
|
+
header: headerBuilder,
|
|
6
|
+
query: queryBuilder,
|
|
7
|
+
path: pathBuilder,
|
|
8
|
+
formData: formDataBuilder
|
|
9
|
+
}; // Add the body to the request
|
|
10
|
+
|
|
11
|
+
function bodyBuilder(_ref) {
|
|
12
|
+
var req = _ref.req,
|
|
13
|
+
value = _ref.value;
|
|
14
|
+
req.body = value;
|
|
15
|
+
} // Add a form data object.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function formDataBuilder(_ref2) {
|
|
19
|
+
var req = _ref2.req,
|
|
20
|
+
value = _ref2.value,
|
|
21
|
+
parameter = _ref2.parameter;
|
|
22
|
+
|
|
23
|
+
if (value || parameter.allowEmptyValue) {
|
|
24
|
+
req.form = req.form || {};
|
|
25
|
+
req.form[parameter.name] = {
|
|
26
|
+
value: value,
|
|
27
|
+
allowEmptyValue: parameter.allowEmptyValue,
|
|
28
|
+
collectionFormat: parameter.collectionFormat
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
} // Add a header to the request
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function headerBuilder(_ref3) {
|
|
35
|
+
var req = _ref3.req,
|
|
36
|
+
parameter = _ref3.parameter,
|
|
37
|
+
value = _ref3.value;
|
|
38
|
+
req.headers = req.headers || {};
|
|
39
|
+
|
|
40
|
+
if (typeof value !== 'undefined') {
|
|
41
|
+
req.headers[parameter.name] = value;
|
|
42
|
+
}
|
|
43
|
+
} // Replace path paramters, with values ( ie: the URL )
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
function pathBuilder(_ref4) {
|
|
47
|
+
var req = _ref4.req,
|
|
48
|
+
value = _ref4.value,
|
|
49
|
+
parameter = _ref4.parameter;
|
|
50
|
+
req.url = req.url.split("{".concat(parameter.name, "}")).join(encodeURIComponent(value));
|
|
51
|
+
} // Add a query to the `query` object, which will later be stringified into the URL's search
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function queryBuilder(_ref5) {
|
|
55
|
+
var req = _ref5.req,
|
|
56
|
+
value = _ref5.value,
|
|
57
|
+
parameter = _ref5.parameter;
|
|
58
|
+
req.query = req.query || {};
|
|
59
|
+
|
|
60
|
+
if (value === false && parameter.type === 'boolean') {
|
|
61
|
+
value = 'false';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (value === 0 && ['number', 'integer'].indexOf(parameter.type) > -1) {
|
|
65
|
+
value = '0';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (value) {
|
|
69
|
+
req.query[parameter.name] = {
|
|
70
|
+
collectionFormat: parameter.collectionFormat,
|
|
71
|
+
value: value
|
|
72
|
+
};
|
|
73
|
+
} else if (parameter.allowEmptyValue && value !== undefined) {
|
|
74
|
+
var paramName = parameter.name;
|
|
75
|
+
req.query[paramName] = req.query[paramName] || {};
|
|
76
|
+
req.query[paramName].allowEmptyValue = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
package/es/helpers.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime-corejs2/helpers/createForOfIteratorHelper";
|
|
2
|
+
import _typeof from "@babel/runtime-corejs2/helpers/typeof";
|
|
3
|
+
import isObject from 'lodash/isObject';
|
|
4
|
+
import startsWith from 'lodash/startsWith';
|
|
5
|
+
|
|
6
|
+
var toLower = function toLower(str) {
|
|
7
|
+
return String.prototype.toLowerCase.call(str);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
var escapeString = function escapeString(str) {
|
|
11
|
+
return str.replace(/[^\w]/gi, '_');
|
|
12
|
+
}; // Spec version detection
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function isOAS3(spec) {
|
|
16
|
+
var oasVersion = spec.openapi;
|
|
17
|
+
|
|
18
|
+
if (!oasVersion) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return startsWith(oasVersion, '3');
|
|
23
|
+
}
|
|
24
|
+
export function isSwagger2(spec) {
|
|
25
|
+
var swaggerVersion = spec.swagger;
|
|
26
|
+
|
|
27
|
+
if (!swaggerVersion) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return startsWith(swaggerVersion, '2');
|
|
32
|
+
} // Strategy for determining operationId
|
|
33
|
+
|
|
34
|
+
export function opId(operation, pathName) {
|
|
35
|
+
var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
36
|
+
|
|
37
|
+
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
38
|
+
v2OperationIdCompatibilityMode = _ref.v2OperationIdCompatibilityMode;
|
|
39
|
+
|
|
40
|
+
if (!operation || _typeof(operation) !== 'object') {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var idWithoutWhitespace = (operation.operationId || '').replace(/\s/g, '');
|
|
45
|
+
|
|
46
|
+
if (idWithoutWhitespace.length) {
|
|
47
|
+
return escapeString(operation.operationId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return idFromPathMethod(pathName, method, {
|
|
51
|
+
v2OperationIdCompatibilityMode: v2OperationIdCompatibilityMode
|
|
52
|
+
});
|
|
53
|
+
} // Create a generated operationId from pathName + method
|
|
54
|
+
|
|
55
|
+
export function idFromPathMethod(pathName, method) {
|
|
56
|
+
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
57
|
+
v2OperationIdCompatibilityMode = _ref2.v2OperationIdCompatibilityMode;
|
|
58
|
+
|
|
59
|
+
if (v2OperationIdCompatibilityMode) {
|
|
60
|
+
var res = "".concat(method.toLowerCase(), "_").concat(pathName).replace(/[\s!@#$%^&*()_+=[{\]};:<>|./?,\\'""-]/g, '_');
|
|
61
|
+
res = res || "".concat(pathName.substring(1), "_").concat(method);
|
|
62
|
+
return res.replace(/((_){2,})/g, '_').replace(/^(_)*/g, '').replace(/([_])*$/g, '');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return "".concat(toLower(method)).concat(escapeString(pathName));
|
|
66
|
+
}
|
|
67
|
+
export function legacyIdFromPathMethod(pathName, method) {
|
|
68
|
+
return "".concat(toLower(method), "-").concat(pathName);
|
|
69
|
+
} // Get the operation, based on operationId ( just return the object, no inheritence )
|
|
70
|
+
|
|
71
|
+
export function getOperationRaw(spec, id) {
|
|
72
|
+
if (!spec || !spec.paths) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return findOperation(spec, function (_ref3) {
|
|
77
|
+
var pathName = _ref3.pathName,
|
|
78
|
+
method = _ref3.method,
|
|
79
|
+
operation = _ref3.operation;
|
|
80
|
+
|
|
81
|
+
if (!operation || _typeof(operation) !== 'object') {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var rawOperationId = operation.operationId; // straight from the source
|
|
86
|
+
|
|
87
|
+
var operationId = opId(operation, pathName, method);
|
|
88
|
+
var legacyOperationId = legacyIdFromPathMethod(pathName, method);
|
|
89
|
+
return [operationId, legacyOperationId, rawOperationId].some(function (val) {
|
|
90
|
+
return val && val === id;
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
} // Will stop iterating over the operations and return the operationObj
|
|
94
|
+
// as soon as predicate returns true
|
|
95
|
+
|
|
96
|
+
export function findOperation(spec, predicate) {
|
|
97
|
+
return eachOperation(spec, predicate, true) || null;
|
|
98
|
+
} // iterate over each operation, and fire a callback with details
|
|
99
|
+
// `find=true` will stop iterating, when the cb returns truthy
|
|
100
|
+
|
|
101
|
+
export function eachOperation(spec, cb, find) {
|
|
102
|
+
if (!spec || _typeof(spec) !== 'object' || !spec.paths || _typeof(spec.paths) !== 'object') {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var paths = spec.paths; // Iterate over the spec, collecting operations
|
|
107
|
+
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
108
|
+
|
|
109
|
+
for (var pathName in paths) {
|
|
110
|
+
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
111
|
+
for (var method in paths[pathName]) {
|
|
112
|
+
if (method.toUpperCase() === 'PARAMETERS') {
|
|
113
|
+
continue; // eslint-disable-line no-continue
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var operation = paths[pathName][method];
|
|
117
|
+
|
|
118
|
+
if (!operation || _typeof(operation) !== 'object') {
|
|
119
|
+
continue; // eslint-disable-line no-continue
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var operationObj = {
|
|
123
|
+
spec: spec,
|
|
124
|
+
pathName: pathName,
|
|
125
|
+
method: method.toUpperCase(),
|
|
126
|
+
operation: operation
|
|
127
|
+
};
|
|
128
|
+
var cbValue = cb(operationObj);
|
|
129
|
+
|
|
130
|
+
if (find && cbValue) {
|
|
131
|
+
return operationObj;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return undefined;
|
|
137
|
+
} // REVIEW: OAS3: identify normalization steps that need changes
|
|
138
|
+
// ...maybe create `normalizeOAS3`?
|
|
139
|
+
|
|
140
|
+
export function normalizeSwagger(parsedSpec) {
|
|
141
|
+
var spec = parsedSpec.spec;
|
|
142
|
+
var paths = spec.paths;
|
|
143
|
+
var map = {};
|
|
144
|
+
|
|
145
|
+
if (!paths || spec.$$normalized) {
|
|
146
|
+
return parsedSpec;
|
|
147
|
+
} // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
for (var pathName in paths) {
|
|
151
|
+
var path = paths[pathName];
|
|
152
|
+
|
|
153
|
+
if (!isObject(path)) {
|
|
154
|
+
continue; // eslint-disable-line no-continue
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var pathParameters = path.parameters; // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
158
|
+
|
|
159
|
+
var _loop = function _loop(method) {
|
|
160
|
+
var operation = path[method];
|
|
161
|
+
|
|
162
|
+
if (!isObject(operation)) {
|
|
163
|
+
return "continue"; // eslint-disable-line no-continue
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
var oid = opId(operation, pathName, method);
|
|
167
|
+
|
|
168
|
+
if (oid) {
|
|
169
|
+
if (map[oid]) {
|
|
170
|
+
map[oid].push(operation);
|
|
171
|
+
} else {
|
|
172
|
+
map[oid] = [operation];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var opList = map[oid];
|
|
176
|
+
|
|
177
|
+
if (opList.length > 1) {
|
|
178
|
+
opList.forEach(function (o, i) {
|
|
179
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
180
|
+
o.__originalOperationId = o.__originalOperationId || o.operationId;
|
|
181
|
+
o.operationId = "".concat(oid).concat(i + 1);
|
|
182
|
+
});
|
|
183
|
+
} else if (typeof operation.operationId !== 'undefined') {
|
|
184
|
+
// Ensure we always add the normalized operation ID if one already exists
|
|
185
|
+
// ( potentially different, given that we normalize our IDs)
|
|
186
|
+
// ... _back_ to the spec. Otherwise, they might not line up
|
|
187
|
+
var obj = opList[0]; // eslint-disable-next-line no-underscore-dangle
|
|
188
|
+
|
|
189
|
+
obj.__originalOperationId = obj.__originalOperationId || operation.operationId;
|
|
190
|
+
obj.operationId = oid;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (method !== 'parameters') {
|
|
195
|
+
// Add inherited consumes, produces, parameters, securities
|
|
196
|
+
var inheritsList = [];
|
|
197
|
+
var toBeInherit = {}; // Global-levels
|
|
198
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
199
|
+
|
|
200
|
+
for (var key in spec) {
|
|
201
|
+
if (key === 'produces' || key === 'consumes' || key === 'security') {
|
|
202
|
+
toBeInherit[key] = spec[key];
|
|
203
|
+
inheritsList.push(toBeInherit);
|
|
204
|
+
}
|
|
205
|
+
} // Path-levels
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
if (pathParameters) {
|
|
209
|
+
toBeInherit.parameters = pathParameters;
|
|
210
|
+
inheritsList.push(toBeInherit);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (inheritsList.length) {
|
|
214
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
215
|
+
var _iterator = _createForOfIteratorHelper(inheritsList),
|
|
216
|
+
_step;
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
220
|
+
var inherits = _step.value;
|
|
221
|
+
|
|
222
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
223
|
+
for (var inheritName in inherits) {
|
|
224
|
+
if (!operation[inheritName]) {
|
|
225
|
+
operation[inheritName] = inherits[inheritName];
|
|
226
|
+
} else if (inheritName === 'parameters') {
|
|
227
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
228
|
+
var _iterator2 = _createForOfIteratorHelper(inherits[inheritName]),
|
|
229
|
+
_step2;
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
var _loop2 = function _loop2() {
|
|
233
|
+
var param = _step2.value;
|
|
234
|
+
var exists = operation[inheritName].some(function (opParam) {
|
|
235
|
+
return opParam.name && opParam.name === param.name || opParam.$ref && opParam.$ref === param.$ref || opParam.$$ref && opParam.$$ref === param.$$ref || opParam === param;
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (!exists) {
|
|
239
|
+
operation[inheritName].push(param);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
244
|
+
_loop2();
|
|
245
|
+
}
|
|
246
|
+
} catch (err) {
|
|
247
|
+
_iterator2.e(err);
|
|
248
|
+
} finally {
|
|
249
|
+
_iterator2.f();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
} catch (err) {
|
|
255
|
+
_iterator.e(err);
|
|
256
|
+
} finally {
|
|
257
|
+
_iterator.f();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
for (var method in path) {
|
|
264
|
+
var _ret = _loop(method);
|
|
265
|
+
|
|
266
|
+
if (_ret === "continue") continue;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
spec.$$normalized = true;
|
|
271
|
+
return parsedSpec;
|
|
272
|
+
}
|