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.
Files changed (57) hide show
  1. package/README.md +10 -2
  2. package/dist/swagger-client.browser.js +24191 -0
  3. package/dist/swagger-client.browser.min.js +3 -0
  4. package/dist/swagger-client.browser.min.js.map +1 -0
  5. package/es/commonjs.js +9 -0
  6. package/es/constants.js +2 -0
  7. package/es/execute/index.js +391 -0
  8. package/es/execute/oas3/build-request.js +149 -0
  9. package/es/execute/oas3/content-serializer.js +18 -0
  10. package/es/execute/oas3/parameter-builders.js +119 -0
  11. package/es/execute/oas3/style-serializer.js +232 -0
  12. package/es/execute/swagger2/build-request.js +119 -0
  13. package/es/execute/swagger2/parameter-builders.js +78 -0
  14. package/es/helpers.js +272 -0
  15. package/es/http.js +621 -0
  16. package/es/index.js +116 -0
  17. package/es/interfaces.js +145 -0
  18. package/es/internal/form-data-monkey-patch.js +94 -0
  19. package/es/resolver.js +123 -0
  20. package/es/specmap/helpers.js +62 -0
  21. package/es/specmap/index.js +613 -0
  22. package/es/specmap/lib/all-of.js +81 -0
  23. package/es/specmap/lib/context-tree.js +111 -0
  24. package/es/specmap/lib/create-error.js +24 -0
  25. package/es/specmap/lib/index.js +391 -0
  26. package/es/specmap/lib/parameters.js +31 -0
  27. package/es/specmap/lib/properties.js +23 -0
  28. package/es/specmap/lib/refs.js +516 -0
  29. package/es/subtree-resolver/index.js +92 -0
  30. package/lib/commonjs.js +10 -0
  31. package/lib/constants.js +7 -0
  32. package/lib/execute/index.js +421 -0
  33. package/lib/execute/oas3/build-request.js +161 -0
  34. package/lib/execute/oas3/content-serializer.js +21 -0
  35. package/lib/execute/oas3/parameter-builders.js +138 -0
  36. package/lib/execute/oas3/style-serializer.js +208 -0
  37. package/lib/execute/swagger2/build-request.js +120 -0
  38. package/lib/execute/swagger2/parameter-builders.js +88 -0
  39. package/lib/helpers.js +261 -0
  40. package/lib/http.js +470 -0
  41. package/lib/index.js +142 -0
  42. package/lib/interfaces.js +159 -0
  43. package/lib/internal/form-data-monkey-patch.js +83 -0
  44. package/lib/resolver.js +125 -0
  45. package/lib/specmap/helpers.js +65 -0
  46. package/lib/specmap/index.js +446 -0
  47. package/lib/specmap/lib/all-of.js +89 -0
  48. package/lib/specmap/lib/context-tree.js +111 -0
  49. package/lib/specmap/lib/create-error.js +25 -0
  50. package/lib/specmap/lib/index.js +402 -0
  51. package/lib/specmap/lib/parameters.js +42 -0
  52. package/lib/specmap/lib/properties.js +38 -0
  53. package/lib/specmap/lib/refs.js +509 -0
  54. package/lib/subtree-resolver/index.js +55 -0
  55. package/package.json +80 -106
  56. package/browser/index.js +0 -54
  57. package/dist/index.js +0 -4372
package/es/commonjs.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict'; // eslint-disable-line
2
+
3
+ var _require = require('./index'),
4
+ SwaggerClient = _require.default; // add backwards compatibility with older versions of swagger-ui
5
+ // by exporting one single symbol.
6
+ // Refs https://github.com/swagger-api/swagger-ui/issues/6210
7
+
8
+
9
+ module.exports = SwaggerClient;
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export var ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = 'application/json, application/yaml';
@@ -0,0 +1,391 @@
1
+ import _slicedToArray from "@babel/runtime-corejs2/helpers/slicedToArray";
2
+ import _JSON$stringify from "@babel/runtime-corejs2/core-js/json/stringify";
3
+ import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime-corejs2/helpers/objectWithoutProperties";
5
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
6
+ import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
7
+ import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
8
+ import getIn from 'lodash/get';
9
+ import isPlainObject from 'lodash/isPlainObject';
10
+ import isArray from 'lodash/isArray';
11
+ import url from 'url';
12
+ import cookie from 'cookie';
13
+ import stockHttp, { mergeInQueryOrForm } from '../http';
14
+ import createError from '../specmap/lib/create-error';
15
+ import SWAGGER2_PARAMETER_BUILDERS from './swagger2/parameter-builders';
16
+ import * as OAS3_PARAMETER_BUILDERS from './oas3/parameter-builders';
17
+ import oas3BuildRequest from './oas3/build-request';
18
+ import swagger2BuildRequest from './swagger2/build-request';
19
+ import { getOperationRaw, legacyIdFromPathMethod, isOAS3 } from '../helpers';
20
+
21
+ var arrayOrEmpty = function arrayOrEmpty(ar) {
22
+ return _Array$isArray(ar) ? ar : [];
23
+ };
24
+
25
+ var OperationNotFoundError = createError('OperationNotFoundError', function cb(message, extra, oriError) {
26
+ this.originalError = oriError;
27
+
28
+ _Object$assign(this, extra || {});
29
+ });
30
+
31
+ var findParametersWithName = function findParametersWithName(name, parameters) {
32
+ return parameters.filter(function (p) {
33
+ return p.name === name;
34
+ });
35
+ }; // removes parameters that have duplicate 'in' and 'name' properties
36
+
37
+
38
+ var deduplicateParameters = function deduplicateParameters(parameters) {
39
+ var paramsMap = {};
40
+ parameters.forEach(function (p) {
41
+ if (!paramsMap[p.in]) {
42
+ paramsMap[p.in] = {};
43
+ }
44
+
45
+ paramsMap[p.in][p.name] = p;
46
+ });
47
+ var dedupedParameters = [];
48
+
49
+ _Object$keys(paramsMap).forEach(function (i) {
50
+ _Object$keys(paramsMap[i]).forEach(function (p) {
51
+ dedupedParameters.push(paramsMap[i][p]);
52
+ });
53
+ });
54
+
55
+ return dedupedParameters;
56
+ }; // For stubbing in tests
57
+
58
+
59
+ export var self = {
60
+ buildRequest: buildRequest
61
+ }; // Execute request, with the given operationId and parameters
62
+ // pathName/method or operationId is optional
63
+
64
+ export function execute(_ref) {
65
+ var userHttp = _ref.http,
66
+ fetch = _ref.fetch,
67
+ spec = _ref.spec,
68
+ operationId = _ref.operationId,
69
+ pathName = _ref.pathName,
70
+ method = _ref.method,
71
+ parameters = _ref.parameters,
72
+ securities = _ref.securities,
73
+ extras = _objectWithoutProperties(_ref, ["http", "fetch", "spec", "operationId", "pathName", "method", "parameters", "securities"]);
74
+
75
+ // Provide default fetch implementation
76
+ var http = userHttp || fetch || stockHttp; // Default to _our_ http
77
+
78
+ if (pathName && method && !operationId) {
79
+ operationId = legacyIdFromPathMethod(pathName, method);
80
+ }
81
+
82
+ var request = self.buildRequest(_objectSpread({
83
+ spec: spec,
84
+ operationId: operationId,
85
+ parameters: parameters,
86
+ securities: securities,
87
+ http: http
88
+ }, extras));
89
+
90
+ if (request.body && (isPlainObject(request.body) || isArray(request.body))) {
91
+ request.body = _JSON$stringify(request.body);
92
+ } // Build request and execute it
93
+
94
+
95
+ return http(request);
96
+ } // Build a request, which can be handled by the `http.js` implementation.
97
+
98
+ export function buildRequest(options) {
99
+ var spec = options.spec,
100
+ operationId = options.operationId,
101
+ responseContentType = options.responseContentType,
102
+ scheme = options.scheme,
103
+ requestInterceptor = options.requestInterceptor,
104
+ responseInterceptor = options.responseInterceptor,
105
+ contextUrl = options.contextUrl,
106
+ userFetch = options.userFetch,
107
+ server = options.server,
108
+ serverVariables = options.serverVariables,
109
+ http = options.http;
110
+ var parameters = options.parameters,
111
+ parameterBuilders = options.parameterBuilders;
112
+ var specIsOAS3 = isOAS3(spec);
113
+
114
+ if (!parameterBuilders) {
115
+ // user did not provide custom parameter builders
116
+ if (specIsOAS3) {
117
+ parameterBuilders = OAS3_PARAMETER_BUILDERS;
118
+ } else {
119
+ parameterBuilders = SWAGGER2_PARAMETER_BUILDERS;
120
+ }
121
+ } // Set credentials with 'http.withCredentials' value
122
+
123
+
124
+ var credentials = http && http.withCredentials ? 'include' : 'same-origin'; // Base Template
125
+
126
+ var req = {
127
+ url: '',
128
+ credentials: credentials,
129
+ headers: {},
130
+ cookies: {}
131
+ };
132
+
133
+ if (requestInterceptor) {
134
+ req.requestInterceptor = requestInterceptor;
135
+ }
136
+
137
+ if (responseInterceptor) {
138
+ req.responseInterceptor = responseInterceptor;
139
+ }
140
+
141
+ if (userFetch) {
142
+ req.userFetch = userFetch;
143
+ }
144
+
145
+ var operationRaw = getOperationRaw(spec, operationId);
146
+
147
+ if (!operationRaw) {
148
+ throw new OperationNotFoundError("Operation ".concat(operationId, " not found"));
149
+ }
150
+
151
+ var _operationRaw$operati = operationRaw.operation,
152
+ operation = _operationRaw$operati === void 0 ? {} : _operationRaw$operati,
153
+ method = operationRaw.method,
154
+ pathName = operationRaw.pathName;
155
+ req.url += baseUrl({
156
+ spec: spec,
157
+ scheme: scheme,
158
+ contextUrl: contextUrl,
159
+ server: server,
160
+ serverVariables: serverVariables,
161
+ pathName: pathName,
162
+ method: method
163
+ }); // Mostly for testing
164
+
165
+ if (!operationId) {
166
+ // Not removing req.cookies causes testing issues and would
167
+ // change our interface, so we're always sure to remove it.
168
+ // See the same statement lower down in this function for
169
+ // more context.
170
+ delete req.cookies;
171
+ return req;
172
+ }
173
+
174
+ req.url += pathName; // Have not yet replaced the path parameters
175
+
176
+ req.method = "".concat(method).toUpperCase();
177
+ parameters = parameters || {};
178
+ var path = spec.paths[pathName] || {};
179
+
180
+ if (responseContentType) {
181
+ req.headers.accept = responseContentType;
182
+ }
183
+
184
+ var combinedParameters = deduplicateParameters([].concat(arrayOrEmpty(operation.parameters)) // operation parameters
185
+ .concat(arrayOrEmpty(path.parameters))); // path parameters
186
+ // REVIEW: OAS3: have any key names or parameter shapes changed?
187
+ // Any new features that need to be plugged in here?
188
+ // Add values to request
189
+
190
+ combinedParameters.forEach(function (parameter) {
191
+ var builder = parameterBuilders[parameter.in];
192
+ var value;
193
+
194
+ if (parameter.in === 'body' && parameter.schema && parameter.schema.properties) {
195
+ value = parameters;
196
+ }
197
+
198
+ value = parameter && parameter.name && parameters[parameter.name];
199
+
200
+ if (typeof value === 'undefined') {
201
+ // check for `name-in` formatted key
202
+ value = parameter && parameter.name && parameters["".concat(parameter.in, ".").concat(parameter.name)];
203
+ } else if (findParametersWithName(parameter.name, combinedParameters).length > 1) {
204
+ // value came from `parameters[parameter.name]`
205
+ // check to see if this is an ambiguous parameter
206
+ // eslint-disable-next-line no-console
207
+ console.warn("Parameter '".concat(parameter.name, "' is ambiguous because the defined spec has more than one parameter with the name: '").concat(parameter.name, "' and the passed-in parameter values did not define an 'in' value."));
208
+ }
209
+
210
+ if (value === null) {
211
+ return;
212
+ }
213
+
214
+ if (typeof parameter.default !== 'undefined' && typeof value === 'undefined') {
215
+ value = parameter.default;
216
+ }
217
+
218
+ if (typeof value === 'undefined' && parameter.required && !parameter.allowEmptyValue) {
219
+ throw new Error("Required parameter ".concat(parameter.name, " is not provided"));
220
+ }
221
+
222
+ if (specIsOAS3 && parameter.schema && parameter.schema.type === 'object' && typeof value === 'string') {
223
+ try {
224
+ value = JSON.parse(value);
225
+ } catch (e) {
226
+ throw new Error('Could not parse object parameter value string as JSON');
227
+ }
228
+ }
229
+
230
+ if (builder) {
231
+ builder({
232
+ req: req,
233
+ parameter: parameter,
234
+ value: value,
235
+ operation: operation,
236
+ spec: spec
237
+ });
238
+ }
239
+ }); // Do version-specific tasks, then return those results.
240
+
241
+ var versionSpecificOptions = _objectSpread(_objectSpread({}, options), {}, {
242
+ operation: operation
243
+ });
244
+
245
+ if (specIsOAS3) {
246
+ req = oas3BuildRequest(versionSpecificOptions, req);
247
+ } else {
248
+ // If not OAS3, then treat as Swagger2.
249
+ req = swagger2BuildRequest(versionSpecificOptions, req);
250
+ } // If the cookie convenience object exists in our request,
251
+ // serialize its content and then delete the cookie object.
252
+
253
+
254
+ if (req.cookies && _Object$keys(req.cookies).length) {
255
+ var cookieString = _Object$keys(req.cookies).reduce(function (prev, cookieName) {
256
+ var cookieValue = req.cookies[cookieName];
257
+ var prefix = prev ? '&' : '';
258
+ var stringified = cookie.serialize(cookieName, cookieValue);
259
+ return prev + prefix + stringified;
260
+ }, '');
261
+
262
+ req.headers.Cookie = cookieString;
263
+ }
264
+
265
+ if (req.cookies) {
266
+ // even if no cookies were defined, we need to remove
267
+ // the cookies key from our request, or many many legacy
268
+ // tests will break.
269
+ delete req.cookies;
270
+ } // Will add the query object into the URL, if it exists
271
+ // ... will also create a FormData instance, if multipart/form-data (eg: a file)
272
+
273
+
274
+ mergeInQueryOrForm(req);
275
+ return req;
276
+ }
277
+
278
+ var stripNonAlpha = function stripNonAlpha(str) {
279
+ return str ? str.replace(/\W/g, '') : null;
280
+ }; // be careful when modifying this! it is a publicly-exposed method.
281
+
282
+
283
+ export function baseUrl(obj) {
284
+ var specIsOAS3 = isOAS3(obj.spec);
285
+ return specIsOAS3 ? oas3BaseUrl(obj) : swagger2BaseUrl(obj);
286
+ }
287
+
288
+ function oas3BaseUrl(_ref2) {
289
+ var spec = _ref2.spec,
290
+ pathName = _ref2.pathName,
291
+ method = _ref2.method,
292
+ server = _ref2.server,
293
+ contextUrl = _ref2.contextUrl,
294
+ _ref2$serverVariables = _ref2.serverVariables,
295
+ serverVariables = _ref2$serverVariables === void 0 ? {} : _ref2$serverVariables;
296
+ var servers = getIn(spec, ['paths', pathName, (method || '').toLowerCase(), 'servers']) || getIn(spec, ['paths', pathName, 'servers']) || getIn(spec, ['servers']);
297
+ var selectedServerUrl = '';
298
+ var selectedServerObj = null;
299
+
300
+ if (server && servers && servers.length) {
301
+ var serverUrls = servers.map(function (srv) {
302
+ return srv.url;
303
+ });
304
+
305
+ if (serverUrls.indexOf(server) > -1) {
306
+ selectedServerUrl = server;
307
+ selectedServerObj = servers[serverUrls.indexOf(server)];
308
+ }
309
+ }
310
+
311
+ if (!selectedServerUrl && servers && servers.length) {
312
+ // default to the first server if we don't have one by now
313
+ selectedServerUrl = servers[0].url; // eslint-disable-line semi
314
+
315
+ var _servers = _slicedToArray(servers, 1);
316
+
317
+ selectedServerObj = _servers[0];
318
+ }
319
+
320
+ if (selectedServerUrl.indexOf('{') > -1) {
321
+ // do variable substitution
322
+ var varNames = getVariableTemplateNames(selectedServerUrl);
323
+ varNames.forEach(function (vari) {
324
+ if (selectedServerObj.variables && selectedServerObj.variables[vari]) {
325
+ // variable is defined in server
326
+ var variableDefinition = selectedServerObj.variables[vari];
327
+ var variableValue = serverVariables[vari] || variableDefinition.default;
328
+ var re = new RegExp("{".concat(vari, "}"), 'g');
329
+ selectedServerUrl = selectedServerUrl.replace(re, variableValue);
330
+ }
331
+ });
332
+ }
333
+
334
+ return buildOas3UrlWithContext(selectedServerUrl, contextUrl);
335
+ }
336
+
337
+ function buildOas3UrlWithContext() {
338
+ var ourUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
339
+ var contextUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
340
+ var parsedUrl = url.parse(ourUrl);
341
+ var parsedContextUrl = url.parse(contextUrl);
342
+ var computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol) || '';
343
+ var computedHost = parsedUrl.host || parsedContextUrl.host;
344
+ var computedPath = parsedUrl.pathname || '';
345
+ var res;
346
+
347
+ if (computedScheme && computedHost) {
348
+ res = "".concat(computedScheme, "://").concat(computedHost + computedPath); // If last character is '/', trim it off
349
+ } else {
350
+ res = computedPath;
351
+ }
352
+
353
+ return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
354
+ }
355
+
356
+ function getVariableTemplateNames(str) {
357
+ var results = [];
358
+ var re = /{([^}]+)}/g;
359
+ var text; // eslint-disable-next-line no-cond-assign
360
+
361
+ while (text = re.exec(str)) {
362
+ results.push(text[1]);
363
+ }
364
+
365
+ return results;
366
+ } // Compose the baseUrl ( scheme + host + basePath )
367
+
368
+
369
+ function swagger2BaseUrl(_ref3) {
370
+ var spec = _ref3.spec,
371
+ scheme = _ref3.scheme,
372
+ _ref3$contextUrl = _ref3.contextUrl,
373
+ contextUrl = _ref3$contextUrl === void 0 ? '' : _ref3$contextUrl;
374
+ var parsedContextUrl = url.parse(contextUrl);
375
+ var firstSchemeInSpec = _Array$isArray(spec.schemes) ? spec.schemes[0] : null;
376
+ var computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http';
377
+ var computedHost = spec.host || parsedContextUrl.host || '';
378
+ var computedPath = spec.basePath || '';
379
+ var res;
380
+
381
+ if (computedScheme && computedHost) {
382
+ // we have what we need for an absolute URL
383
+ res = "".concat(computedScheme, "://").concat(computedHost + computedPath);
384
+ } else {
385
+ // if not, a relative URL will have to do
386
+ res = computedPath;
387
+ } // If last character is '/', trim it off
388
+
389
+
390
+ return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
391
+ }
@@ -0,0 +1,149 @@
1
+ import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
2
+ import _typeof from "@babel/runtime-corejs2/helpers/typeof";
3
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
4
+ // This function runs after the common function,
5
+ // `src/execute/index.js#buildRequest`
6
+ import assign from 'lodash/assign';
7
+ import get from 'lodash/get';
8
+ import btoa from 'btoa';
9
+ export default function buildRequest(options, req) {
10
+ var operation = options.operation,
11
+ requestBody = options.requestBody,
12
+ securities = options.securities,
13
+ spec = options.spec,
14
+ attachContentTypeForEmptyPayload = options.attachContentTypeForEmptyPayload;
15
+ var requestContentType = options.requestContentType;
16
+ req = applySecurities({
17
+ request: req,
18
+ securities: securities,
19
+ operation: operation,
20
+ spec: spec
21
+ });
22
+ var requestBodyDef = operation.requestBody || {};
23
+
24
+ var requestBodyMediaTypes = _Object$keys(requestBodyDef.content || {});
25
+
26
+ var isExplicitContentTypeValid = requestContentType && requestBodyMediaTypes.indexOf(requestContentType) > -1; // for OAS3: set the Content-Type
27
+
28
+ if (requestBody || attachContentTypeForEmptyPayload) {
29
+ // does the passed requestContentType appear in the requestBody definition?
30
+ if (requestContentType && isExplicitContentTypeValid) {
31
+ req.headers['Content-Type'] = requestContentType;
32
+ } else if (!requestContentType) {
33
+ var firstMediaType = requestBodyMediaTypes[0];
34
+
35
+ if (firstMediaType) {
36
+ req.headers['Content-Type'] = firstMediaType;
37
+ requestContentType = firstMediaType;
38
+ }
39
+ }
40
+ } else if (requestContentType && isExplicitContentTypeValid) {
41
+ req.headers['Content-Type'] = requestContentType;
42
+ } // for OAS3: add requestBody to request
43
+
44
+
45
+ if (requestBody) {
46
+ if (requestContentType) {
47
+ if (requestBodyMediaTypes.indexOf(requestContentType) > -1) {
48
+ // only attach body if the requestBody has a definition for the
49
+ // contentType that has been explicitly set
50
+ if (requestContentType === 'application/x-www-form-urlencoded' || requestContentType === 'multipart/form-data') {
51
+ if (_typeof(requestBody) === 'object') {
52
+ var encoding = (requestBodyDef.content[requestContentType] || {}).encoding || {};
53
+ req.form = {};
54
+
55
+ _Object$keys(requestBody).forEach(function (k) {
56
+ req.form[k] = {
57
+ value: requestBody[k],
58
+ encoding: encoding[k] || {}
59
+ };
60
+ });
61
+ } else {
62
+ req.form = requestBody;
63
+ }
64
+ } else {
65
+ req.body = requestBody;
66
+ }
67
+ }
68
+ } else {
69
+ req.body = requestBody;
70
+ }
71
+ }
72
+
73
+ return req;
74
+ } // Add security values, to operations - that declare their need on them
75
+ // Adapted from the Swagger2 implementation
76
+
77
+ export function applySecurities(_ref) {
78
+ var request = _ref.request,
79
+ _ref$securities = _ref.securities,
80
+ securities = _ref$securities === void 0 ? {} : _ref$securities,
81
+ _ref$operation = _ref.operation,
82
+ operation = _ref$operation === void 0 ? {} : _ref$operation,
83
+ spec = _ref.spec;
84
+ var result = assign({}, request);
85
+ var _securities$authorize = securities.authorized,
86
+ authorized = _securities$authorize === void 0 ? {} : _securities$authorize;
87
+ var security = operation.security || spec.security || [];
88
+ var isAuthorized = authorized && !!_Object$keys(authorized).length;
89
+ var securityDef = get(spec, ['components', 'securitySchemes']) || {};
90
+ result.headers = result.headers || {};
91
+ result.query = result.query || {};
92
+
93
+ if (!_Object$keys(securities).length || !isAuthorized || !security || _Array$isArray(operation.security) && !operation.security.length) {
94
+ return request;
95
+ }
96
+
97
+ security.forEach(function (securityObj) {
98
+ _Object$keys(securityObj).forEach(function (key) {
99
+ var auth = authorized[key];
100
+ var schema = securityDef[key];
101
+
102
+ if (!auth) {
103
+ return;
104
+ }
105
+
106
+ var value = auth.value || auth;
107
+ var type = schema.type;
108
+
109
+ if (auth) {
110
+ if (type === 'apiKey') {
111
+ if (schema.in === 'query') {
112
+ result.query[schema.name] = value;
113
+ }
114
+
115
+ if (schema.in === 'header') {
116
+ result.headers[schema.name] = value;
117
+ }
118
+
119
+ if (schema.in === 'cookie') {
120
+ result.cookies[schema.name] = value;
121
+ }
122
+ } else if (type === 'http') {
123
+ if (/^basic$/i.test(schema.scheme)) {
124
+ var username = value.username || '';
125
+ var password = value.password || '';
126
+ var encoded = btoa("".concat(username, ":").concat(password));
127
+ result.headers.Authorization = "Basic ".concat(encoded);
128
+ }
129
+
130
+ if (/^bearer$/i.test(schema.scheme)) {
131
+ result.headers.Authorization = "Bearer ".concat(value);
132
+ }
133
+ } else if (type === 'oauth2') {
134
+ var token = auth.token || {};
135
+ var tokenName = schema['x-tokenName'] || 'access_token';
136
+ var tokenValue = token[tokenName];
137
+ var tokenType = token.token_type;
138
+
139
+ if (!tokenType || tokenType.toLowerCase() === 'bearer') {
140
+ tokenType = 'Bearer';
141
+ }
142
+
143
+ result.headers.Authorization = "".concat(tokenType, " ").concat(tokenValue);
144
+ }
145
+ }
146
+ });
147
+ });
148
+ return result;
149
+ }
@@ -0,0 +1,18 @@
1
+ import _JSON$stringify from "@babel/runtime-corejs2/core-js/json/stringify";
2
+
3
+ /*
4
+ Serializer that serializes according to a media type instead of OpenAPI's
5
+ `style` + `explode` constructs.
6
+ */
7
+ export default function serialize(value, mediaType) {
8
+ if (mediaType.includes('application/json')) {
9
+ if (typeof value === 'string') {
10
+ // Assume the user has a JSON string
11
+ return value;
12
+ }
13
+
14
+ return _JSON$stringify(value);
15
+ }
16
+
17
+ return value.toString();
18
+ }
@@ -0,0 +1,119 @@
1
+ import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
2
+ import _typeof from "@babel/runtime-corejs2/helpers/typeof";
3
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
4
+ import pick from 'lodash/pick';
5
+ import stylize, { encodeDisallowedCharacters } from './style-serializer';
6
+ import serialize from './content-serializer';
7
+ export function path(_ref) {
8
+ var req = _ref.req,
9
+ value = _ref.value,
10
+ parameter = _ref.parameter;
11
+ var name = parameter.name,
12
+ style = parameter.style,
13
+ explode = parameter.explode,
14
+ content = parameter.content;
15
+
16
+ if (content) {
17
+ var effectiveMediaType = _Object$keys(content)[0];
18
+
19
+ req.url = req.url.split("{".concat(name, "}")).join(encodeDisallowedCharacters(serialize(value, effectiveMediaType), {
20
+ escape: true
21
+ }));
22
+ return;
23
+ }
24
+
25
+ var styledValue = stylize({
26
+ key: parameter.name,
27
+ value: value,
28
+ style: style || 'simple',
29
+ explode: explode || false,
30
+ escape: true
31
+ });
32
+ req.url = req.url.split("{".concat(name, "}")).join(styledValue);
33
+ }
34
+ export function query(_ref2) {
35
+ var req = _ref2.req,
36
+ value = _ref2.value,
37
+ parameter = _ref2.parameter;
38
+ req.query = req.query || {};
39
+
40
+ if (parameter.content) {
41
+ var effectiveMediaType = _Object$keys(parameter.content)[0];
42
+
43
+ req.query[parameter.name] = serialize(value, effectiveMediaType);
44
+ return;
45
+ }
46
+
47
+ if (value === false) {
48
+ value = 'false';
49
+ }
50
+
51
+ if (value === 0) {
52
+ value = '0';
53
+ }
54
+
55
+ if (value) {
56
+ req.query[parameter.name] = {
57
+ value: value,
58
+ serializationOption: pick(parameter, ['style', 'explode', 'allowReserved'])
59
+ };
60
+ } else if (parameter.allowEmptyValue && value !== undefined) {
61
+ var paramName = parameter.name;
62
+ req.query[paramName] = req.query[paramName] || {};
63
+ req.query[paramName].allowEmptyValue = true;
64
+ }
65
+ }
66
+ var PARAMETER_HEADER_BLACKLIST = ['accept', 'authorization', 'content-type'];
67
+ export function header(_ref3) {
68
+ var req = _ref3.req,
69
+ parameter = _ref3.parameter,
70
+ value = _ref3.value;
71
+ req.headers = req.headers || {};
72
+
73
+ if (PARAMETER_HEADER_BLACKLIST.indexOf(parameter.name.toLowerCase()) > -1) {
74
+ return;
75
+ }
76
+
77
+ if (parameter.content) {
78
+ var effectiveMediaType = _Object$keys(parameter.content)[0];
79
+
80
+ req.headers[parameter.name] = serialize(value, effectiveMediaType);
81
+ return;
82
+ }
83
+
84
+ if (typeof value !== 'undefined') {
85
+ req.headers[parameter.name] = stylize({
86
+ key: parameter.name,
87
+ value: value,
88
+ style: parameter.style || 'simple',
89
+ explode: typeof parameter.explode === 'undefined' ? false : parameter.explode,
90
+ escape: false
91
+ });
92
+ }
93
+ }
94
+ export function cookie(_ref4) {
95
+ var req = _ref4.req,
96
+ parameter = _ref4.parameter,
97
+ value = _ref4.value;
98
+ req.headers = req.headers || {};
99
+
100
+ var type = _typeof(value);
101
+
102
+ if (parameter.content) {
103
+ var effectiveMediaType = _Object$keys(parameter.content)[0];
104
+
105
+ req.headers.Cookie = "".concat(parameter.name, "=").concat(serialize(value, effectiveMediaType));
106
+ return;
107
+ }
108
+
109
+ if (type !== 'undefined') {
110
+ var prefix = type === 'object' && !_Array$isArray(value) && parameter.explode ? '' : "".concat(parameter.name, "=");
111
+ req.headers.Cookie = prefix + stylize({
112
+ key: parameter.name,
113
+ value: value,
114
+ escape: false,
115
+ style: parameter.style || 'form',
116
+ explode: typeof parameter.explode === 'undefined' ? false : parameter.explode
117
+ });
118
+ }
119
+ }