@p7m/ldap-backend 0.1.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.
@@ -0,0 +1,703 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _superagent = _interopRequireDefault(require("superagent"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
15
+ * WiFi Account Backend
16
+ * Manage WiFi accounts via LDAP directory
17
+ *
18
+ * The version of the OpenAPI document: 0.1.0
19
+ * Contact: tech@p7m.de
20
+ *
21
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
22
+ * https://openapi-generator.tech
23
+ * Do not edit the class manually.
24
+ *
25
+ */
26
+ /**
27
+ * @module ApiClient
28
+ * @version 0.1.0
29
+ */
30
+ /**
31
+ * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
32
+ * application to use this class directly - the *Api and model classes provide the public API for the service. The
33
+ * contents of this file should be regarded as internal but are documented for completeness.
34
+ * @alias module:ApiClient
35
+ * @class
36
+ */
37
+ var ApiClient = /*#__PURE__*/function () {
38
+ /**
39
+ * The base URL against which to resolve every API call's (relative) path.
40
+ * Overrides the default value set in spec file if present
41
+ * @param {String} basePath
42
+ */
43
+ function ApiClient() {
44
+ var basePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'https://ldap.api.p7m.de/v1';
45
+ _classCallCheck(this, ApiClient);
46
+ /**
47
+ * The base URL against which to resolve every API call's (relative) path.
48
+ * @type {String}
49
+ * @default https://ldap.api.p7m.de/v1
50
+ */
51
+ this.basePath = basePath.replace(/\/+$/, '');
52
+
53
+ /**
54
+ * The authentication methods to be included for all API calls.
55
+ * @type {Array.<String>}
56
+ */
57
+ this.authentications = {
58
+ 'oauth': {
59
+ type: 'oauth2'
60
+ }
61
+ };
62
+
63
+ /**
64
+ * The default HTTP headers to be included for all API calls.
65
+ * @type {Array.<String>}
66
+ * @default {}
67
+ */
68
+ this.defaultHeaders = {
69
+ 'User-Agent': 'OpenAPI-Generator/0.1.0/Javascript'
70
+ };
71
+
72
+ /**
73
+ * The default HTTP timeout for all API calls.
74
+ * @type {Number}
75
+ * @default 60000
76
+ */
77
+ this.timeout = 60000;
78
+
79
+ /**
80
+ * If set to false an additional timestamp parameter is added to all API GET calls to
81
+ * prevent browser caching
82
+ * @type {Boolean}
83
+ * @default true
84
+ */
85
+ this.cache = true;
86
+
87
+ /**
88
+ * If set to true, the client will save the cookies from each server
89
+ * response, and return them in the next request.
90
+ * @default false
91
+ */
92
+ this.enableCookies = false;
93
+
94
+ /*
95
+ * Used to save and return cookies in a node.js (non-browser) setting,
96
+ * if this.enableCookies is set to true.
97
+ */
98
+ if (typeof window === 'undefined') {
99
+ this.agent = new _superagent["default"].agent();
100
+ }
101
+
102
+ /*
103
+ * Allow user to override superagent agent
104
+ */
105
+ this.requestAgent = null;
106
+
107
+ /*
108
+ * Allow user to add superagent plugins
109
+ */
110
+ this.plugins = null;
111
+ }
112
+
113
+ /**
114
+ * Returns a string representation for an actual parameter.
115
+ * @param param The actual parameter.
116
+ * @returns {String} The string representation of <code>param</code>.
117
+ */
118
+ return _createClass(ApiClient, [{
119
+ key: "paramToString",
120
+ value: function paramToString(param) {
121
+ if (param == undefined || param == null) {
122
+ return '';
123
+ }
124
+ if (param instanceof Date) {
125
+ return param.toJSON();
126
+ }
127
+ if (ApiClient.canBeJsonified(param)) {
128
+ return JSON.stringify(param);
129
+ }
130
+ return param.toString();
131
+ }
132
+
133
+ /**
134
+ * Returns a boolean indicating if the parameter could be JSON.stringified
135
+ * @param param The actual parameter
136
+ * @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
137
+ */
138
+ }, {
139
+ key: "buildUrl",
140
+ value:
141
+ /**
142
+ * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
143
+ * NOTE: query parameters are not handled here.
144
+ * @param {String} path The path to append to the base URL.
145
+ * @param {Object} pathParams The parameter values to append.
146
+ * @param {String} apiBasePath Base path defined in the path, operation level to override the default one
147
+ * @returns {String} The encoded path with parameter values substituted.
148
+ */
149
+ function buildUrl(path, pathParams, apiBasePath) {
150
+ var _this = this;
151
+ if (!path.match(/^\//)) {
152
+ path = '/' + path;
153
+ }
154
+ var url = this.basePath + path;
155
+
156
+ // use API (operation, path) base path if defined
157
+ if (apiBasePath !== null && apiBasePath !== undefined) {
158
+ url = apiBasePath + path;
159
+ }
160
+ url = url.replace(/\{([\w-\.#]+)\}/g, function (fullMatch, key) {
161
+ var value;
162
+ if (pathParams.hasOwnProperty(key)) {
163
+ value = _this.paramToString(pathParams[key]);
164
+ } else {
165
+ value = fullMatch;
166
+ }
167
+ return encodeURIComponent(value);
168
+ });
169
+ return url;
170
+ }
171
+
172
+ /**
173
+ * Checks whether the given content type represents JSON.<br>
174
+ * JSON content type examples:<br>
175
+ * <ul>
176
+ * <li>application/json</li>
177
+ * <li>application/json; charset=UTF8</li>
178
+ * <li>APPLICATION/JSON</li>
179
+ * </ul>
180
+ * @param {String} contentType The MIME content type to check.
181
+ * @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
182
+ */
183
+ }, {
184
+ key: "isJsonMime",
185
+ value: function isJsonMime(contentType) {
186
+ return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
187
+ }
188
+
189
+ /**
190
+ * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
191
+ * @param {Array.<String>} contentTypes
192
+ * @returns {String} The chosen content type, preferring JSON.
193
+ */
194
+ }, {
195
+ key: "jsonPreferredMime",
196
+ value: function jsonPreferredMime(contentTypes) {
197
+ for (var i = 0; i < contentTypes.length; i++) {
198
+ if (this.isJsonMime(contentTypes[i])) {
199
+ return contentTypes[i];
200
+ }
201
+ }
202
+ return contentTypes[0];
203
+ }
204
+
205
+ /**
206
+ * Checks whether the given parameter value represents file-like content.
207
+ * @param param The parameter to check.
208
+ * @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
209
+ */
210
+ }, {
211
+ key: "isFileParam",
212
+ value: function isFileParam(param) {
213
+ // fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
214
+ if (typeof require === 'function') {
215
+ var fs;
216
+ try {
217
+ fs = require('fs');
218
+ } catch (err) {}
219
+ if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
220
+ return true;
221
+ }
222
+ }
223
+
224
+ // Buffer in Node.js
225
+ if (typeof Buffer === 'function' && param instanceof Buffer) {
226
+ return true;
227
+ }
228
+
229
+ // Blob in browser
230
+ if (typeof Blob === 'function' && param instanceof Blob) {
231
+ return true;
232
+ }
233
+
234
+ // File in browser (it seems File object is also instance of Blob, but keep this for safe)
235
+ if (typeof File === 'function' && param instanceof File) {
236
+ return true;
237
+ }
238
+ return false;
239
+ }
240
+
241
+ /**
242
+ * Normalizes parameter values:
243
+ * <ul>
244
+ * <li>remove nils</li>
245
+ * <li>keep files and arrays</li>
246
+ * <li>format to string with `paramToString` for other cases</li>
247
+ * </ul>
248
+ * @param {Object.<String, Object>} params The parameters as object properties.
249
+ * @returns {Object.<String, Object>} normalized parameters.
250
+ */
251
+ }, {
252
+ key: "normalizeParams",
253
+ value: function normalizeParams(params) {
254
+ var newParams = {};
255
+ for (var key in params) {
256
+ if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
257
+ var value = params[key];
258
+ if (this.isFileParam(value) || Array.isArray(value)) {
259
+ newParams[key] = value;
260
+ } else {
261
+ newParams[key] = this.paramToString(value);
262
+ }
263
+ }
264
+ }
265
+ return newParams;
266
+ }
267
+
268
+ /**
269
+ * Builds a string representation of an array-type actual parameter, according to the given collection format.
270
+ * @param {Array} param An array parameter.
271
+ * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
272
+ * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
273
+ * <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
274
+ */
275
+ }, {
276
+ key: "buildCollectionParam",
277
+ value: function buildCollectionParam(param, collectionFormat) {
278
+ if (param == null) {
279
+ return null;
280
+ }
281
+ switch (collectionFormat) {
282
+ case 'csv':
283
+ return param.map(this.paramToString, this).join(',');
284
+ case 'ssv':
285
+ return param.map(this.paramToString, this).join(' ');
286
+ case 'tsv':
287
+ return param.map(this.paramToString, this).join('\t');
288
+ case 'pipes':
289
+ return param.map(this.paramToString, this).join('|');
290
+ case 'multi':
291
+ //return the array directly as SuperAgent will handle it as expected
292
+ return param.map(this.paramToString, this);
293
+ case 'passthrough':
294
+ return param;
295
+ default:
296
+ throw new Error('Unknown collection format: ' + collectionFormat);
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Applies authentication headers to the request.
302
+ * @param {Object} request The request object created by a <code>superagent()</code> call.
303
+ * @param {Array.<String>} authNames An array of authentication method names.
304
+ */
305
+ }, {
306
+ key: "applyAuthToRequest",
307
+ value: function applyAuthToRequest(request, authNames) {
308
+ var _this2 = this;
309
+ authNames.forEach(function (authName) {
310
+ var auth = _this2.authentications[authName];
311
+ switch (auth.type) {
312
+ case 'basic':
313
+ if (auth.username || auth.password) {
314
+ request.auth(auth.username || '', auth.password || '');
315
+ }
316
+ break;
317
+ case 'bearer':
318
+ if (auth.accessToken) {
319
+ var localVarBearerToken = typeof auth.accessToken === 'function' ? auth.accessToken() : auth.accessToken;
320
+ request.set({
321
+ 'Authorization': 'Bearer ' + localVarBearerToken
322
+ });
323
+ }
324
+ break;
325
+ case 'apiKey':
326
+ if (auth.apiKey) {
327
+ var data = {};
328
+ if (auth.apiKeyPrefix) {
329
+ data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
330
+ } else {
331
+ data[auth.name] = auth.apiKey;
332
+ }
333
+ if (auth['in'] === 'header') {
334
+ request.set(data);
335
+ } else {
336
+ request.query(data);
337
+ }
338
+ }
339
+ break;
340
+ case 'oauth2':
341
+ if (auth.accessToken) {
342
+ request.set({
343
+ 'Authorization': 'Bearer ' + auth.accessToken
344
+ });
345
+ }
346
+ break;
347
+ default:
348
+ throw new Error('Unknown authentication type: ' + auth.type);
349
+ }
350
+ });
351
+ }
352
+
353
+ /**
354
+ * Deserializes an HTTP response body into a value of the specified type.
355
+ * @param {Object} response A SuperAgent response object.
356
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
357
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
358
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
359
+ * all properties on <code>data<code> will be converted to this type.
360
+ * @returns A value of the specified type.
361
+ */
362
+ }, {
363
+ key: "deserialize",
364
+ value: function deserialize(response, returnType) {
365
+ if (response == null || returnType == null || response.status == 204) {
366
+ return null;
367
+ }
368
+
369
+ // Rely on SuperAgent for parsing response body.
370
+ // See http://visionmedia.github.io/superagent/#parsing-response-bodies
371
+ var data = response.body;
372
+ if (data == null || _typeof(data) === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length) {
373
+ // SuperAgent does not always produce a body; use the unparsed response as a fallback
374
+ data = response.text;
375
+ }
376
+ return ApiClient.convertToType(data, returnType);
377
+ }
378
+
379
+ /**
380
+ * Invokes the REST service using the supplied settings and parameters.
381
+ * @param {String} path The base URL to invoke.
382
+ * @param {String} httpMethod The HTTP method to use.
383
+ * @param {Object.<String, String>} pathParams A map of path parameters and their values.
384
+ * @param {Object.<String, Object>} queryParams A map of query parameters and their values.
385
+ * @param {Object.<String, Object>} headerParams A map of header parameters and their values.
386
+ * @param {Object.<String, Object>} formParams A map of form parameters and their values.
387
+ * @param {Object} bodyParam The value to pass as the request body.
388
+ * @param {Array.<String>} authNames An array of authentication type names.
389
+ * @param {Array.<String>} contentTypes An array of request MIME types.
390
+ * @param {Array.<String>} accepts An array of acceptable response MIME types.
391
+ * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
392
+ * constructor for a complex type.
393
+ * @param {String} apiBasePath base path defined in the operation/path level to override the default one
394
+ * @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
395
+ */
396
+ }, {
397
+ key: "callApi",
398
+ value: function callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, apiBasePath) {
399
+ var _this3 = this;
400
+ var url = this.buildUrl(path, pathParams, apiBasePath);
401
+ var request = (0, _superagent["default"])(httpMethod, url);
402
+ if (this.plugins !== null) {
403
+ for (var index in this.plugins) {
404
+ if (this.plugins.hasOwnProperty(index)) {
405
+ request.use(this.plugins[index]);
406
+ }
407
+ }
408
+ }
409
+
410
+ // apply authentications
411
+ this.applyAuthToRequest(request, authNames);
412
+
413
+ // set query parameters
414
+ if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
415
+ queryParams['_'] = new Date().getTime();
416
+ }
417
+ request.query(this.normalizeParams(queryParams));
418
+
419
+ // set header parameters
420
+ request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
421
+
422
+ // set requestAgent if it is set by user
423
+ if (this.requestAgent) {
424
+ request.agent(this.requestAgent);
425
+ }
426
+
427
+ // set request timeout
428
+ request.timeout(this.timeout);
429
+ var contentType = this.jsonPreferredMime(contentTypes);
430
+ if (contentType) {
431
+ // Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746)
432
+ if (contentType != 'multipart/form-data') {
433
+ request.type(contentType);
434
+ }
435
+ }
436
+ if (contentType === 'application/x-www-form-urlencoded') {
437
+ var normalizedParams = this.normalizeParams(formParams);
438
+ var urlSearchParams = new URLSearchParams(normalizedParams);
439
+ var queryString = urlSearchParams.toString();
440
+ request.send(queryString);
441
+ } else if (contentType == 'multipart/form-data') {
442
+ var _formParams = this.normalizeParams(formParams);
443
+ for (var key in _formParams) {
444
+ if (_formParams.hasOwnProperty(key)) {
445
+ var _formParamsValue = _formParams[key];
446
+ if (this.isFileParam(_formParamsValue)) {
447
+ // file field
448
+ request.attach(key, _formParamsValue);
449
+ } else if (Array.isArray(_formParamsValue) && _formParamsValue.length && this.isFileParam(_formParamsValue[0])) {
450
+ // multiple files
451
+ _formParamsValue.forEach(function (file) {
452
+ return request.attach(key, file);
453
+ });
454
+ } else {
455
+ request.field(key, _formParamsValue);
456
+ }
457
+ }
458
+ }
459
+ } else if (bodyParam !== null && bodyParam !== undefined) {
460
+ if (!request.header['Content-Type']) {
461
+ request.type('application/json');
462
+ }
463
+ request.send(bodyParam);
464
+ }
465
+ var accept = this.jsonPreferredMime(accepts);
466
+ if (accept) {
467
+ request.accept(accept);
468
+ }
469
+ if (returnType === 'Blob') {
470
+ request.responseType('blob');
471
+ } else if (returnType === 'String') {
472
+ request.responseType('text');
473
+ }
474
+
475
+ // Attach previously saved cookies, if enabled
476
+ if (this.enableCookies) {
477
+ if (typeof window === 'undefined') {
478
+ this.agent._attachCookies(request);
479
+ } else {
480
+ request.withCredentials();
481
+ }
482
+ }
483
+ return new Promise(function (resolve, reject) {
484
+ request.end(function (error, response) {
485
+ if (error) {
486
+ var err = {};
487
+ if (response) {
488
+ err.status = response.status;
489
+ err.statusText = response.statusText;
490
+ err.body = response.body;
491
+ err.response = response;
492
+ }
493
+ err.error = error;
494
+ reject(err);
495
+ } else {
496
+ try {
497
+ var data = _this3.deserialize(response, returnType);
498
+ if (_this3.enableCookies && typeof window === 'undefined') {
499
+ _this3.agent._saveCookies(response);
500
+ }
501
+ resolve({
502
+ data: data,
503
+ response: response
504
+ });
505
+ } catch (err) {
506
+ reject(err);
507
+ }
508
+ }
509
+ });
510
+ });
511
+ }
512
+
513
+ /**
514
+ * Parses an ISO-8601 string representation or epoch representation of a date value.
515
+ * @param {String} str The date value as a string.
516
+ * @returns {Date} The parsed date object.
517
+ */
518
+ }, {
519
+ key: "hostSettings",
520
+ value:
521
+ /**
522
+ * Gets an array of host settings
523
+ * @returns An array of host settings
524
+ */
525
+ function hostSettings() {
526
+ return [{
527
+ 'url': "https://ldap.api.p7m.de/v1",
528
+ 'description': "No description provided"
529
+ }];
530
+ }
531
+ }, {
532
+ key: "getBasePathFromSettings",
533
+ value: function getBasePathFromSettings(index) {
534
+ var variables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
535
+ var servers = this.hostSettings();
536
+
537
+ // check array index out of bound
538
+ if (index < 0 || index >= servers.length) {
539
+ throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
540
+ }
541
+ var server = servers[index];
542
+ var url = server['url'];
543
+
544
+ // go through variable and assign a value
545
+ for (var variable_name in server['variables']) {
546
+ if (variable_name in variables) {
547
+ var variable = server['variables'][variable_name];
548
+ if (!('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name])) {
549
+ url = url.replace("{" + variable_name + "}", variables[variable_name]);
550
+ } else {
551
+ throw new Error("The variable `" + variable_name + "` in the host URL has invalid value " + variables[variable_name] + ". Must be " + server['variables'][variable_name]['enum_values'] + ".");
552
+ }
553
+ } else {
554
+ // use default value
555
+ url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']);
556
+ }
557
+ }
558
+ return url;
559
+ }
560
+
561
+ /**
562
+ * Constructs a new map or array model from REST data.
563
+ * @param data {Object|Array} The REST data.
564
+ * @param obj {Object|Array} The target object or array.
565
+ */
566
+ }], [{
567
+ key: "canBeJsonified",
568
+ value: function canBeJsonified(str) {
569
+ if (typeof str !== 'string' && _typeof(str) !== 'object') return false;
570
+ try {
571
+ var type = str.toString();
572
+ return type === '[object Object]' || type === '[object Array]';
573
+ } catch (err) {
574
+ return false;
575
+ }
576
+ }
577
+ }, {
578
+ key: "parseDate",
579
+ value: function parseDate(str) {
580
+ if (isNaN(str)) {
581
+ return new Date(str.replace(/(\d)(T)(\d)/i, '$1 $3'));
582
+ }
583
+ return new Date(+str);
584
+ }
585
+
586
+ /**
587
+ * Converts a value to the specified type.
588
+ * @param {(String|Object)} data The data to convert, as a string or object.
589
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
590
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
591
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
592
+ * all properties on <code>data<code> will be converted to this type.
593
+ * @returns An instance of the specified type or null or undefined if data is null or undefined.
594
+ */
595
+ }, {
596
+ key: "convertToType",
597
+ value: function convertToType(data, type) {
598
+ if (data === null || data === undefined) return data;
599
+ switch (type) {
600
+ case 'Boolean':
601
+ return Boolean(data);
602
+ case 'Integer':
603
+ return parseInt(data, 10);
604
+ case 'Number':
605
+ return parseFloat(data);
606
+ case 'String':
607
+ return String(data);
608
+ case 'Date':
609
+ return ApiClient.parseDate(String(data));
610
+ case 'Blob':
611
+ return data;
612
+ default:
613
+ if (type === Object) {
614
+ // generic object, return directly
615
+ return data;
616
+ } else if (typeof type.constructFromObject === 'function') {
617
+ // for model type like User and enum class
618
+ return type.constructFromObject(data);
619
+ } else if (Array.isArray(type)) {
620
+ // for array type like: ['String']
621
+ var itemType = type[0];
622
+ return data.map(function (item) {
623
+ return ApiClient.convertToType(item, itemType);
624
+ });
625
+ } else if (_typeof(type) === 'object') {
626
+ // for plain object type like: {'String': 'Integer'}
627
+ var keyType, valueType;
628
+ for (var k in type) {
629
+ if (type.hasOwnProperty(k)) {
630
+ keyType = k;
631
+ valueType = type[k];
632
+ break;
633
+ }
634
+ }
635
+ var result = {};
636
+ for (var k in data) {
637
+ if (data.hasOwnProperty(k)) {
638
+ var key = ApiClient.convertToType(k, keyType);
639
+ var value = ApiClient.convertToType(data[k], valueType);
640
+ result[key] = value;
641
+ }
642
+ }
643
+ return result;
644
+ } else {
645
+ // for unknown type, return the data directly
646
+ return data;
647
+ }
648
+ }
649
+ }
650
+ }, {
651
+ key: "constructFromObject",
652
+ value: function constructFromObject(data, obj, itemType) {
653
+ if (Array.isArray(data)) {
654
+ for (var i = 0; i < data.length; i++) {
655
+ if (data.hasOwnProperty(i)) obj[i] = ApiClient.convertToType(data[i], itemType);
656
+ }
657
+ } else {
658
+ for (var k in data) {
659
+ if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
660
+ }
661
+ }
662
+ }
663
+ }]);
664
+ }();
665
+ /**
666
+ * Enumeration of collection format separator strategies.
667
+ * @enum {String}
668
+ * @readonly
669
+ */
670
+ ApiClient.CollectionFormatEnum = {
671
+ /**
672
+ * Comma-separated values. Value: <code>csv</code>
673
+ * @const
674
+ */
675
+ CSV: ',',
676
+ /**
677
+ * Space-separated values. Value: <code>ssv</code>
678
+ * @const
679
+ */
680
+ SSV: ' ',
681
+ /**
682
+ * Tab-separated values. Value: <code>tsv</code>
683
+ * @const
684
+ */
685
+ TSV: '\t',
686
+ /**
687
+ * Pipe(|)-separated values. Value: <code>pipes</code>
688
+ * @const
689
+ */
690
+ PIPES: '|',
691
+ /**
692
+ * Native array. Value: <code>multi</code>
693
+ * @const
694
+ */
695
+ MULTI: 'multi'
696
+ };
697
+
698
+ /**
699
+ * The default API client implementation.
700
+ * @type {module:ApiClient}
701
+ */
702
+ ApiClient.instance = new ApiClient();
703
+ var _default = exports["default"] = ApiClient;