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
@@ -0,0 +1,111 @@
1
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
2
+ import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
3
+ import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime-corejs2/helpers/createClass";
5
+
6
+ var ContextTree = /*#__PURE__*/function () {
7
+ function ContextTree(value) {
8
+ _classCallCheck(this, ContextTree);
9
+
10
+ this.root = createNode(value || {});
11
+ }
12
+
13
+ _createClass(ContextTree, [{
14
+ key: "set",
15
+ value: function set(path, value) {
16
+ var parent = this.getParent(path, true);
17
+
18
+ if (!parent) {
19
+ updateNode(this.root, value, null);
20
+ return;
21
+ }
22
+
23
+ var key = path[path.length - 1];
24
+ var children = parent.children;
25
+
26
+ if (children[key]) {
27
+ updateNode(children[key], value, parent);
28
+ return;
29
+ }
30
+
31
+ children[key] = createNode(value, parent);
32
+ } // Get the "best" node (node or nearest parent) and return its value.
33
+
34
+ }, {
35
+ key: "get",
36
+ value: function get(path) {
37
+ path = path || [];
38
+
39
+ if (path.length < 1) {
40
+ return this.root.value;
41
+ }
42
+
43
+ var branch = this.root;
44
+ var child;
45
+ var token;
46
+
47
+ for (var i = 0; i < path.length; i += 1) {
48
+ token = path[i];
49
+ child = branch.children;
50
+
51
+ if (!child[token]) {
52
+ break;
53
+ }
54
+
55
+ branch = child[token];
56
+ }
57
+
58
+ return branch && branch.protoValue;
59
+ }
60
+ }, {
61
+ key: "getParent",
62
+ value: function getParent(path, ensureExists) {
63
+ if (!path || path.length < 1) {
64
+ return null;
65
+ }
66
+
67
+ if (path.length < 2) {
68
+ return this.root;
69
+ }
70
+
71
+ return path.slice(0, -1).reduce(function (branch, token) {
72
+ if (!branch) {
73
+ return branch;
74
+ }
75
+
76
+ var children = branch.children;
77
+
78
+ if (!children[token] && ensureExists) {
79
+ children[token] = createNode(null, branch);
80
+ }
81
+
82
+ return children[token];
83
+ }, this.root);
84
+ }
85
+ }]);
86
+
87
+ return ContextTree;
88
+ }(); // =========================
89
+ // Utilities
90
+ // =========================
91
+
92
+
93
+ export { ContextTree as default };
94
+
95
+ function createNode(value, parent) {
96
+ return updateNode({
97
+ children: {}
98
+ }, value, parent);
99
+ }
100
+
101
+ function updateNode(node, value, parent) {
102
+ node.value = value || {};
103
+ node.protoValue = parent ? _objectSpread(_objectSpread({}, parent.protoValue), node.value) : node.value;
104
+
105
+ _Object$keys(node.children).forEach(function (prop) {
106
+ var child = node.children[prop];
107
+ node.children[prop] = updateNode(child, child.value, node);
108
+ });
109
+
110
+ return node;
111
+ }
@@ -0,0 +1,24 @@
1
+ export default function createErrorType(name, init) {
2
+ function E() {
3
+ if (!Error.captureStackTrace) {
4
+ this.stack = new Error().stack;
5
+ } else {
6
+ Error.captureStackTrace(this, this.constructor);
7
+ }
8
+
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+
13
+ this.message = args[0];
14
+
15
+ if (init) {
16
+ init.apply(this, args);
17
+ }
18
+ }
19
+
20
+ E.prototype = new Error();
21
+ E.prototype.name = name;
22
+ E.prototype.constructor = E;
23
+ return E;
24
+ }
@@ -0,0 +1,391 @@
1
+ import _typeof from "@babel/runtime-corejs2/helpers/typeof";
2
+ import _toConsumableArray from "@babel/runtime-corejs2/helpers/toConsumableArray";
3
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
4
+ import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty";
5
+ import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
6
+ import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
7
+ import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
8
+ import * as jsonPatch from 'fast-json-patch';
9
+ import deepExtend from 'deep-extend';
10
+ import cloneDeep from 'lodash/cloneDeep';
11
+ export default {
12
+ add: add,
13
+ replace: replace,
14
+ remove: remove,
15
+ merge: merge,
16
+ mergeDeep: mergeDeep,
17
+ context: context,
18
+ getIn: getIn,
19
+ applyPatch: applyPatch,
20
+ parentPathMatch: parentPathMatch,
21
+ flatten: flatten,
22
+ fullyNormalizeArray: fullyNormalizeArray,
23
+ normalizeArray: normalizeArray,
24
+ isPromise: isPromise,
25
+ forEachNew: forEachNew,
26
+ forEachNewPrimitive: forEachNewPrimitive,
27
+ isJsonPatch: isJsonPatch,
28
+ isContextPatch: isContextPatch,
29
+ isPatch: isPatch,
30
+ isMutation: isMutation,
31
+ isAdditiveMutation: isAdditiveMutation,
32
+ isGenerator: isGenerator,
33
+ isFunction: isFunction,
34
+ isObject: isObject,
35
+ isError: isError
36
+ };
37
+
38
+ function applyPatch(obj, patch, opts) {
39
+ opts = opts || {};
40
+ patch = _objectSpread(_objectSpread({}, patch), {}, {
41
+ path: patch.path && normalizeJSONPath(patch.path)
42
+ });
43
+
44
+ if (patch.op === 'merge') {
45
+ var newValue = getInByJsonPath(obj, patch.path);
46
+
47
+ _Object$assign(newValue, patch.value);
48
+
49
+ jsonPatch.applyPatch(obj, [replace(patch.path, newValue)]);
50
+ } else if (patch.op === 'mergeDeep') {
51
+ var currentValue = getInByJsonPath(obj, patch.path); // Iterate the properties of the patch
52
+ // eslint-disable-next-line no-restricted-syntax, guard-for-in
53
+
54
+ for (var prop in patch.value) {
55
+ var propVal = patch.value[prop];
56
+
57
+ var isArray = _Array$isArray(propVal);
58
+
59
+ if (isArray) {
60
+ // deepExtend doesn't merge arrays, so we will do it manually
61
+ var existing = currentValue[prop] || [];
62
+ currentValue[prop] = existing.concat(propVal);
63
+ } else if (isObject(propVal) && !isArray) {
64
+ // If it's an object, iterate it's keys and merge
65
+ // if there are conflicting keys, merge deep, otherwise shallow merge
66
+ var currentObj = _objectSpread({}, currentValue[prop]); // eslint-disable-next-line no-restricted-syntax
67
+
68
+
69
+ for (var key in propVal) {
70
+ if (Object.prototype.hasOwnProperty.call(currentObj, key)) {
71
+ // if there is a single conflicting key, just deepExtend the entire value
72
+ // and break from the loop (since all future keys are also merged)
73
+ // We do this because we can't deepExtend two primitives
74
+ // (currentObj[key] & propVal[key] may be primitives).
75
+ //
76
+ // we also deeply assign here, since we aren't in control of
77
+ // how deepExtend affects existing nested objects
78
+ currentObj = deepExtend(cloneDeep(currentObj), propVal);
79
+ break;
80
+ } else {
81
+ _Object$assign(currentObj, _defineProperty({}, key, propVal[key]));
82
+ }
83
+ }
84
+
85
+ currentValue[prop] = currentObj;
86
+ } else {
87
+ // It's a primitive, just replace existing
88
+ currentValue[prop] = propVal;
89
+ }
90
+ }
91
+ } else if (patch.op === 'add' && patch.path === '' && isObject(patch.value)) {
92
+ // { op: 'add', path: '', value: { a: 1, b: 2 }}
93
+ // has no effect: json patch refuses to do anything.
94
+ // so let's break that patch down into a set of patches,
95
+ // one for each key in the intended root value.
96
+ var patches = _Object$keys(patch.value).reduce(function (arr, key) {
97
+ arr.push({
98
+ op: 'add',
99
+ path: "/".concat(normalizeJSONPath(key)),
100
+ value: patch.value[key]
101
+ });
102
+ return arr;
103
+ }, []);
104
+
105
+ jsonPatch.applyPatch(obj, patches);
106
+ } else if (patch.op === 'replace' && patch.path === '') {
107
+ var _patch = patch,
108
+ value = _patch.value;
109
+
110
+ if (opts.allowMetaPatches && patch.meta && isAdditiveMutation(patch) && (_Array$isArray(patch.value) || isObject(patch.value))) {
111
+ value = _objectSpread(_objectSpread({}, value), patch.meta);
112
+ }
113
+
114
+ obj = value;
115
+ } else {
116
+ jsonPatch.applyPatch(obj, [patch]); // Attach metadata to the resulting value.
117
+
118
+ if (opts.allowMetaPatches && patch.meta && isAdditiveMutation(patch) && (_Array$isArray(patch.value) || isObject(patch.value))) {
119
+ var _currentValue = getInByJsonPath(obj, patch.path);
120
+
121
+ var _newValue = _objectSpread(_objectSpread({}, _currentValue), patch.meta);
122
+
123
+ jsonPatch.applyPatch(obj, [replace(patch.path, _newValue)]);
124
+ }
125
+ }
126
+
127
+ return obj;
128
+ }
129
+
130
+ function normalizeJSONPath(path) {
131
+ if (_Array$isArray(path)) {
132
+ if (path.length < 1) {
133
+ return '';
134
+ }
135
+
136
+ return "/".concat(path.map(function (item) {
137
+ // eslint-disable-line prefer-template
138
+ return (item + '').replace(/~/g, '~0').replace(/\//g, '~1'); // eslint-disable-line prefer-template
139
+ }).join('/'));
140
+ }
141
+
142
+ return path;
143
+ } // =========================
144
+ // JSON-Patch Wrappers
145
+ // =========================
146
+
147
+
148
+ function add(path, value) {
149
+ return {
150
+ op: 'add',
151
+ path: path,
152
+ value: value
153
+ };
154
+ } // function _get(path) {
155
+ // return { op: '_get', path };
156
+ // }
157
+
158
+
159
+ function replace(path, value, meta) {
160
+ return {
161
+ op: 'replace',
162
+ path: path,
163
+ value: value,
164
+ meta: meta
165
+ };
166
+ }
167
+
168
+ function remove(path) {
169
+ return {
170
+ op: 'remove',
171
+ path: path
172
+ };
173
+ } // Custom wrappers
174
+
175
+
176
+ function merge(path, value) {
177
+ return {
178
+ type: 'mutation',
179
+ op: 'merge',
180
+ path: path,
181
+ value: value
182
+ };
183
+ } // Custom wrappers
184
+
185
+
186
+ function mergeDeep(path, value) {
187
+ return {
188
+ type: 'mutation',
189
+ op: 'mergeDeep',
190
+ path: path,
191
+ value: value
192
+ };
193
+ }
194
+
195
+ function context(path, value) {
196
+ return {
197
+ type: 'context',
198
+ path: path,
199
+ value: value
200
+ };
201
+ } // =========================
202
+ // Iterators
203
+ // =========================
204
+
205
+
206
+ function forEachNew(mutations, fn) {
207
+ try {
208
+ return forEachNewPatch(mutations, forEach, fn);
209
+ } catch (e) {
210
+ return e;
211
+ }
212
+ }
213
+
214
+ function forEachNewPrimitive(mutations, fn) {
215
+ try {
216
+ return forEachNewPatch(mutations, forEachPrimitive, fn);
217
+ } catch (e) {
218
+ return e;
219
+ }
220
+ }
221
+
222
+ function forEachNewPatch(mutations, fn, callback) {
223
+ var res = mutations.filter(isAdditiveMutation).map(function (mutation) {
224
+ return fn(mutation.value, callback, mutation.path);
225
+ }) || [];
226
+ var flat = flatten(res);
227
+ var clean = cleanArray(flat);
228
+ return clean;
229
+ }
230
+
231
+ function forEachPrimitive(obj, fn, basePath) {
232
+ basePath = basePath || [];
233
+
234
+ if (_Array$isArray(obj)) {
235
+ return obj.map(function (val, key) {
236
+ return forEachPrimitive(val, fn, basePath.concat(key));
237
+ });
238
+ }
239
+
240
+ if (isObject(obj)) {
241
+ return _Object$keys(obj).map(function (key) {
242
+ return forEachPrimitive(obj[key], fn, basePath.concat(key));
243
+ });
244
+ }
245
+
246
+ return fn(obj, basePath[basePath.length - 1], basePath);
247
+ }
248
+
249
+ function forEach(obj, fn, basePath) {
250
+ basePath = basePath || [];
251
+ var results = [];
252
+
253
+ if (basePath.length > 0) {
254
+ var newResults = fn(obj, basePath[basePath.length - 1], basePath);
255
+
256
+ if (newResults) {
257
+ results = results.concat(newResults);
258
+ }
259
+ }
260
+
261
+ if (_Array$isArray(obj)) {
262
+ var arrayResults = obj.map(function (val, key) {
263
+ return forEach(val, fn, basePath.concat(key));
264
+ });
265
+
266
+ if (arrayResults) {
267
+ results = results.concat(arrayResults);
268
+ }
269
+ } else if (isObject(obj)) {
270
+ var moreResults = _Object$keys(obj).map(function (key) {
271
+ return forEach(obj[key], fn, basePath.concat(key));
272
+ });
273
+
274
+ if (moreResults) {
275
+ results = results.concat(moreResults);
276
+ }
277
+ }
278
+
279
+ results = flatten(results);
280
+ return results;
281
+ } // =========================
282
+ // Paths
283
+ // =========================
284
+
285
+
286
+ function parentPathMatch(path, arr) {
287
+ if (!_Array$isArray(arr)) {
288
+ return false;
289
+ }
290
+
291
+ for (var i = 0, len = arr.length; i < len; i += 1) {
292
+ if (arr[i] !== path[i]) {
293
+ return false;
294
+ }
295
+ }
296
+
297
+ return true;
298
+ }
299
+
300
+ function getIn(obj, path) {
301
+ return path.reduce(function (val, token) {
302
+ if (typeof token !== 'undefined' && val) {
303
+ return val[token];
304
+ }
305
+
306
+ return val;
307
+ }, obj);
308
+ } // =========================
309
+ // Array
310
+ // =========================
311
+
312
+
313
+ function fullyNormalizeArray(arr) {
314
+ return cleanArray(flatten(normalizeArray(arr)));
315
+ }
316
+
317
+ function normalizeArray(arr) {
318
+ return _Array$isArray(arr) ? arr : [arr];
319
+ }
320
+
321
+ function flatten(arr) {
322
+ var _ref;
323
+
324
+ return (_ref = []).concat.apply(_ref, _toConsumableArray(arr.map(function (val) {
325
+ return _Array$isArray(val) ? flatten(val) : val;
326
+ })));
327
+ }
328
+
329
+ function cleanArray(arr) {
330
+ return arr.filter(function (elm) {
331
+ return typeof elm !== 'undefined';
332
+ });
333
+ } // =========================
334
+ // Is-Thing.
335
+ // =========================
336
+
337
+
338
+ function isObject(val) {
339
+ return val && _typeof(val) === 'object';
340
+ }
341
+
342
+ function isPromise(val) {
343
+ return isObject(val) && isFunction(val.then);
344
+ }
345
+
346
+ function isFunction(val) {
347
+ return val && typeof val === 'function';
348
+ }
349
+
350
+ function isError(patch) {
351
+ return patch instanceof Error;
352
+ }
353
+
354
+ function isJsonPatch(patch) {
355
+ if (isPatch(patch)) {
356
+ var op = patch.op;
357
+ return op === 'add' || op === 'remove' || op === 'replace';
358
+ }
359
+
360
+ return false;
361
+ }
362
+
363
+ function isGenerator(thing) {
364
+ return Object.prototype.toString.call(thing) === '[object GeneratorFunction]';
365
+ }
366
+
367
+ function isMutation(patch) {
368
+ return isJsonPatch(patch) || isPatch(patch) && patch.type === 'mutation';
369
+ }
370
+
371
+ function isAdditiveMutation(patch) {
372
+ return isMutation(patch) && (patch.op === 'add' || patch.op === 'replace' || patch.op === 'merge' || patch.op === 'mergeDeep');
373
+ }
374
+
375
+ function isContextPatch(patch) {
376
+ return isPatch(patch) && patch.type === 'context';
377
+ }
378
+
379
+ function isPatch(patch) {
380
+ return patch && _typeof(patch) === 'object';
381
+ }
382
+
383
+ function getInByJsonPath(obj, jsonPath) {
384
+ try {
385
+ return jsonPatch.getValueByPointer(obj, jsonPath);
386
+ } catch (e) {
387
+ console.error(e); // eslint-disable-line no-console
388
+
389
+ return {};
390
+ }
391
+ }
@@ -0,0 +1,31 @@
1
+ import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
2
+ import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
3
+ import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
4
+ import lib from '.';
5
+ export default {
6
+ key: 'parameters',
7
+ plugin: function plugin(parameters, key, fullPath, specmap) {
8
+ if (_Array$isArray(parameters) && parameters.length) {
9
+ var val = _Object$assign([], parameters);
10
+
11
+ var opPath = fullPath.slice(0, -1);
12
+
13
+ var op = _objectSpread({}, lib.getIn(specmap.spec, opPath));
14
+
15
+ parameters.forEach(function (param, i) {
16
+ try {
17
+ val[i].default = specmap.parameterMacro(op, param);
18
+ } catch (e) {
19
+ var err = new Error(e);
20
+ err.fullPath = fullPath;
21
+ return err;
22
+ }
23
+
24
+ return undefined;
25
+ });
26
+ return lib.replace(fullPath, val);
27
+ }
28
+
29
+ return lib.replace(fullPath, parameters);
30
+ }
31
+ };
@@ -0,0 +1,23 @@
1
+ import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
2
+ import lib from '.';
3
+ export default {
4
+ key: 'properties',
5
+ plugin: function plugin(properties, key, fullPath, specmap) {
6
+ var val = _objectSpread({}, properties); // eslint-disable-next-line no-restricted-syntax, guard-for-in
7
+
8
+
9
+ for (var k in properties) {
10
+ try {
11
+ val[k].default = specmap.modelPropertyMacro(val[k]);
12
+ } catch (e) {
13
+ var err = new Error(e);
14
+ err.fullPath = fullPath; // This is an array
15
+
16
+ return err;
17
+ }
18
+ }
19
+
20
+ var patch = lib.replace(fullPath, val);
21
+ return patch;
22
+ }
23
+ };