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/lib/helpers.js ADDED
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.isOAS3 = isOAS3;
5
+ exports.isSwagger2 = isSwagger2;
6
+ exports.opId = opId;
7
+ exports.idFromPathMethod = idFromPathMethod;
8
+ exports.legacyIdFromPathMethod = legacyIdFromPathMethod;
9
+ exports.getOperationRaw = getOperationRaw;
10
+ exports.findOperation = findOperation;
11
+ exports.eachOperation = eachOperation;
12
+ exports.normalizeSwagger = normalizeSwagger;
13
+
14
+ var _isObject = _interopRequireDefault(require("lodash/isObject"));
15
+
16
+ var _startsWith = _interopRequireDefault(require("lodash/startsWith"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const toLower = str => String.prototype.toLowerCase.call(str);
21
+
22
+ const escapeString = str => {
23
+ return str.replace(/[^\w]/gi, '_');
24
+ }; // Spec version detection
25
+
26
+
27
+ function isOAS3(spec) {
28
+ const oasVersion = spec.openapi;
29
+
30
+ if (!oasVersion) {
31
+ return false;
32
+ }
33
+
34
+ return (0, _startsWith.default)(oasVersion, '3');
35
+ }
36
+
37
+ function isSwagger2(spec) {
38
+ const swaggerVersion = spec.swagger;
39
+
40
+ if (!swaggerVersion) {
41
+ return false;
42
+ }
43
+
44
+ return (0, _startsWith.default)(swaggerVersion, '2');
45
+ } // Strategy for determining operationId
46
+
47
+
48
+ function opId(operation, pathName, method = '', {
49
+ v2OperationIdCompatibilityMode
50
+ } = {}) {
51
+ if (!operation || typeof operation !== 'object') {
52
+ return null;
53
+ }
54
+
55
+ const idWithoutWhitespace = (operation.operationId || '').replace(/\s/g, '');
56
+
57
+ if (idWithoutWhitespace.length) {
58
+ return escapeString(operation.operationId);
59
+ }
60
+
61
+ return idFromPathMethod(pathName, method, {
62
+ v2OperationIdCompatibilityMode
63
+ });
64
+ } // Create a generated operationId from pathName + method
65
+
66
+
67
+ function idFromPathMethod(pathName, method, {
68
+ v2OperationIdCompatibilityMode
69
+ } = {}) {
70
+ if (v2OperationIdCompatibilityMode) {
71
+ let res = `${method.toLowerCase()}_${pathName}`.replace(/[\s!@#$%^&*()_+=[{\]};:<>|./?,\\'""-]/g, '_');
72
+ res = res || `${pathName.substring(1)}_${method}`;
73
+ return res.replace(/((_){2,})/g, '_').replace(/^(_)*/g, '').replace(/([_])*$/g, '');
74
+ }
75
+
76
+ return `${toLower(method)}${escapeString(pathName)}`;
77
+ }
78
+
79
+ function legacyIdFromPathMethod(pathName, method) {
80
+ return `${toLower(method)}-${pathName}`;
81
+ } // Get the operation, based on operationId ( just return the object, no inheritence )
82
+
83
+
84
+ function getOperationRaw(spec, id) {
85
+ if (!spec || !spec.paths) {
86
+ return null;
87
+ }
88
+
89
+ return findOperation(spec, ({
90
+ pathName,
91
+ method,
92
+ operation
93
+ }) => {
94
+ if (!operation || typeof operation !== 'object') {
95
+ return false;
96
+ }
97
+
98
+ const rawOperationId = operation.operationId; // straight from the source
99
+
100
+ const operationId = opId(operation, pathName, method);
101
+ const legacyOperationId = legacyIdFromPathMethod(pathName, method);
102
+ return [operationId, legacyOperationId, rawOperationId].some(val => val && val === id);
103
+ });
104
+ } // Will stop iterating over the operations and return the operationObj
105
+ // as soon as predicate returns true
106
+
107
+
108
+ function findOperation(spec, predicate) {
109
+ return eachOperation(spec, predicate, true) || null;
110
+ } // iterate over each operation, and fire a callback with details
111
+ // `find=true` will stop iterating, when the cb returns truthy
112
+
113
+
114
+ function eachOperation(spec, cb, find) {
115
+ if (!spec || typeof spec !== 'object' || !spec.paths || typeof spec.paths !== 'object') {
116
+ return null;
117
+ }
118
+
119
+ const {
120
+ paths
121
+ } = spec; // Iterate over the spec, collecting operations
122
+ // eslint-disable-next-line no-restricted-syntax, guard-for-in
123
+
124
+ for (const pathName in paths) {
125
+ // eslint-disable-next-line no-restricted-syntax, guard-for-in
126
+ for (const method in paths[pathName]) {
127
+ if (method.toUpperCase() === 'PARAMETERS') {
128
+ continue; // eslint-disable-line no-continue
129
+ }
130
+
131
+ const operation = paths[pathName][method];
132
+
133
+ if (!operation || typeof operation !== 'object') {
134
+ continue; // eslint-disable-line no-continue
135
+ }
136
+
137
+ const operationObj = {
138
+ spec,
139
+ pathName,
140
+ method: method.toUpperCase(),
141
+ operation
142
+ };
143
+ const cbValue = cb(operationObj);
144
+
145
+ if (find && cbValue) {
146
+ return operationObj;
147
+ }
148
+ }
149
+ }
150
+
151
+ return undefined;
152
+ } // REVIEW: OAS3: identify normalization steps that need changes
153
+ // ...maybe create `normalizeOAS3`?
154
+
155
+
156
+ function normalizeSwagger(parsedSpec) {
157
+ const {
158
+ spec
159
+ } = parsedSpec;
160
+ const {
161
+ paths
162
+ } = spec;
163
+ const map = {};
164
+
165
+ if (!paths || spec.$$normalized) {
166
+ return parsedSpec;
167
+ } // eslint-disable-next-line no-restricted-syntax, guard-for-in
168
+
169
+
170
+ for (const pathName in paths) {
171
+ const path = paths[pathName];
172
+
173
+ if (!(0, _isObject.default)(path)) {
174
+ continue; // eslint-disable-line no-continue
175
+ }
176
+
177
+ const pathParameters = path.parameters; // eslint-disable-next-line no-restricted-syntax, guard-for-in
178
+
179
+ for (const method in path) {
180
+ const operation = path[method];
181
+
182
+ if (!(0, _isObject.default)(operation)) {
183
+ continue; // eslint-disable-line no-continue
184
+ }
185
+
186
+ const oid = opId(operation, pathName, method);
187
+
188
+ if (oid) {
189
+ if (map[oid]) {
190
+ map[oid].push(operation);
191
+ } else {
192
+ map[oid] = [operation];
193
+ }
194
+
195
+ const opList = map[oid];
196
+
197
+ if (opList.length > 1) {
198
+ opList.forEach((o, i) => {
199
+ // eslint-disable-next-line no-underscore-dangle
200
+ o.__originalOperationId = o.__originalOperationId || o.operationId;
201
+ o.operationId = `${oid}${i + 1}`;
202
+ });
203
+ } else if (typeof operation.operationId !== 'undefined') {
204
+ // Ensure we always add the normalized operation ID if one already exists
205
+ // ( potentially different, given that we normalize our IDs)
206
+ // ... _back_ to the spec. Otherwise, they might not line up
207
+ const obj = opList[0]; // eslint-disable-next-line no-underscore-dangle
208
+
209
+ obj.__originalOperationId = obj.__originalOperationId || operation.operationId;
210
+ obj.operationId = oid;
211
+ }
212
+ }
213
+
214
+ if (method !== 'parameters') {
215
+ // Add inherited consumes, produces, parameters, securities
216
+ const inheritsList = [];
217
+ const toBeInherit = {}; // Global-levels
218
+ // eslint-disable-next-line no-restricted-syntax
219
+
220
+ for (const key in spec) {
221
+ if (key === 'produces' || key === 'consumes' || key === 'security') {
222
+ toBeInherit[key] = spec[key];
223
+ inheritsList.push(toBeInherit);
224
+ }
225
+ } // Path-levels
226
+
227
+
228
+ if (pathParameters) {
229
+ toBeInherit.parameters = pathParameters;
230
+ inheritsList.push(toBeInherit);
231
+ }
232
+
233
+ if (inheritsList.length) {
234
+ // eslint-disable-next-line no-restricted-syntax
235
+ for (const inherits of inheritsList) {
236
+ // eslint-disable-next-line no-restricted-syntax
237
+ for (const inheritName in inherits) {
238
+ if (!operation[inheritName]) {
239
+ operation[inheritName] = inherits[inheritName];
240
+ } else if (inheritName === 'parameters') {
241
+ // eslint-disable-next-line no-restricted-syntax
242
+ for (const param of inherits[inheritName]) {
243
+ const exists = operation[inheritName].some(opParam => {
244
+ return opParam.name && opParam.name === param.name || opParam.$ref && opParam.$ref === param.$ref || opParam.$$ref && opParam.$$ref === param.$$ref || opParam === param;
245
+ });
246
+
247
+ if (!exists) {
248
+ operation[inheritName].push(param);
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
258
+
259
+ spec.$$normalized = true;
260
+ return parsedSpec;
261
+ }