swagger-client 3.19.11 → 3.20.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.
@@ -240,7 +240,7 @@ export function buildRequest(options) {
240
240
  }
241
241
  if (req.cookies) {
242
242
  // even if no cookies were defined, we need to remove
243
- // the cookies key from our request, or many many legacy
243
+ // the cookies key from our request, or many legacy
244
244
  // tests will break.
245
245
  delete req.cookies;
246
246
  }
@@ -63,7 +63,7 @@ export default function buildRequest(options, req) {
63
63
  // contentType that has been explicitly set
64
64
  if (requestContentType === 'application/x-www-form-urlencoded' || requestContentType === 'multipart/form-data') {
65
65
  if (typeof requestBody === 'object') {
66
- const encoding = (requestBodyDef.content[requestContentType] || {}).encoding || {};
66
+ const encoding = requestBodyDef.content[requestContentType]?.encoding ?? {};
67
67
  req.form = {};
68
68
  Object.keys(requestBody).forEach(k => {
69
69
  req.form[k] = {
package/es/http/index.js CHANGED
@@ -182,6 +182,29 @@ const SEPARATORS = {
182
182
  pipes: '|'
183
183
  };
184
184
 
185
+ /**
186
+ * Specialized sub-class of File class, that only
187
+ * accepts string data and retain this data in `data`
188
+ * public property throughout the lifecycle of its instances.
189
+ *
190
+ * This sub-class is exclusively used only when Encoding Object
191
+ * is defined within the Media Type Object (OpenAPI 3.x.y).
192
+ */
193
+ class FileWithData extends File {
194
+ constructor(data) {
195
+ let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
196
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
197
+ super([data], name, options);
198
+ this.data = data;
199
+ }
200
+ valueOf() {
201
+ return this.data;
202
+ }
203
+ toString() {
204
+ return this.valueOf();
205
+ }
206
+ }
207
+
185
208
  // Formats a key-value and returns an array of key-value pairs.
186
209
  //
187
210
  // Return value example 1: [['color', 'blue']]
@@ -230,13 +253,21 @@ function formatKeyValue(key, input) {
230
253
  allowReserved
231
254
  });
232
255
  }
233
- if (encoding.contentType) {
234
- if (encoding.contentType === 'application/json') {
235
- // If value is a string, assume value is already a JSON string
256
+ if (typeof encoding.contentType === 'string') {
257
+ if (encoding.contentType.startsWith('application/json')) {
258
+ // if value is a string, assume value is already a JSON string
236
259
  const json = typeof value === 'string' ? value : JSON.stringify(value);
237
- return [[encodedKey, encodeFn(json)]];
260
+ const encodedJson = encodeFn(json);
261
+ const file = new FileWithData(encodedJson, 'blob', {
262
+ type: encoding.contentType
263
+ });
264
+ return [[encodedKey, file]];
238
265
  }
239
- return [[encodedKey, encodeFn(value.toString())]];
266
+ const encodedData = encodeFn(String(value));
267
+ const blob = new FileWithData(encodedData, 'blob', {
268
+ type: encoding.contentType
269
+ });
270
+ return [[encodedKey, blob]];
240
271
  }
241
272
 
242
273
  // Primitive
@@ -357,7 +388,11 @@ export function encodeFormOrQuery(data) {
357
388
  const encodedQuery = Object.keys(data).reduce((result, parameterName) => {
358
389
  // eslint-disable-next-line no-restricted-syntax
359
390
  for (const [key, value] of formatKeyValue(parameterName, data[parameterName])) {
360
- result[key] = value;
391
+ if (value instanceof FileWithData) {
392
+ result[key] = value.valueOf();
393
+ } else {
394
+ result[key] = value;
395
+ }
361
396
  }
362
397
  return result;
363
398
  }, {});
@@ -256,7 +256,7 @@ function buildRequest(options) {
256
256
  }
257
257
  if (req.cookies) {
258
258
  // even if no cookies were defined, we need to remove
259
- // the cookies key from our request, or many many legacy
259
+ // the cookies key from our request, or many legacy
260
260
  // tests will break.
261
261
  delete req.cookies;
262
262
  }
@@ -68,7 +68,8 @@ function buildRequest(options, req) {
68
68
  // contentType that has been explicitly set
69
69
  if (requestContentType === 'application/x-www-form-urlencoded' || requestContentType === 'multipart/form-data') {
70
70
  if (typeof requestBody === 'object') {
71
- const encoding = (requestBodyDef.content[requestContentType] || {}).encoding || {};
71
+ var _requestBodyDef$conte, _requestBodyDef$conte2;
72
+ const encoding = (_requestBodyDef$conte = (_requestBodyDef$conte2 = requestBodyDef.content[requestContentType]) === null || _requestBodyDef$conte2 === void 0 ? void 0 : _requestBodyDef$conte2.encoding) !== null && _requestBodyDef$conte !== void 0 ? _requestBodyDef$conte : {};
72
73
  req.form = {};
73
74
  Object.keys(requestBody).forEach(k => {
74
75
  req.form[k] = {
package/lib/http/index.js CHANGED
@@ -189,6 +189,27 @@ const SEPARATORS = {
189
189
  pipes: '|'
190
190
  };
191
191
 
192
+ /**
193
+ * Specialized sub-class of File class, that only
194
+ * accepts string data and retain this data in `data`
195
+ * public property throughout the lifecycle of its instances.
196
+ *
197
+ * This sub-class is exclusively used only when Encoding Object
198
+ * is defined within the Media Type Object (OpenAPI 3.x.y).
199
+ */
200
+ class FileWithData extends _formdataNode.File {
201
+ constructor(data, name = '', options = {}) {
202
+ super([data], name, options);
203
+ this.data = data;
204
+ }
205
+ valueOf() {
206
+ return this.data;
207
+ }
208
+ toString() {
209
+ return this.valueOf();
210
+ }
211
+ }
212
+
192
213
  // Formats a key-value and returns an array of key-value pairs.
193
214
  //
194
215
  // Return value example 1: [['color', 'blue']]
@@ -236,13 +257,21 @@ function formatKeyValue(key, input, skipEncoding = false) {
236
257
  allowReserved
237
258
  });
238
259
  }
239
- if (encoding.contentType) {
240
- if (encoding.contentType === 'application/json') {
241
- // If value is a string, assume value is already a JSON string
260
+ if (typeof encoding.contentType === 'string') {
261
+ if (encoding.contentType.startsWith('application/json')) {
262
+ // if value is a string, assume value is already a JSON string
242
263
  const json = typeof value === 'string' ? value : JSON.stringify(value);
243
- return [[encodedKey, encodeFn(json)]];
264
+ const encodedJson = encodeFn(json);
265
+ const file = new FileWithData(encodedJson, 'blob', {
266
+ type: encoding.contentType
267
+ });
268
+ return [[encodedKey, file]];
244
269
  }
245
- return [[encodedKey, encodeFn(value.toString())]];
270
+ const encodedData = encodeFn(String(value));
271
+ const blob = new FileWithData(encodedData, 'blob', {
272
+ type: encoding.contentType
273
+ });
274
+ return [[encodedKey, blob]];
246
275
  }
247
276
 
248
277
  // Primitive
@@ -362,7 +391,11 @@ function encodeFormOrQuery(data) {
362
391
  const encodedQuery = Object.keys(data).reduce((result, parameterName) => {
363
392
  // eslint-disable-next-line no-restricted-syntax
364
393
  for (const [key, value] of formatKeyValue(parameterName, data[parameterName])) {
365
- result[key] = value;
394
+ if (value instanceof FileWithData) {
395
+ result[key] = value.valueOf();
396
+ } else {
397
+ result[key] = value;
398
+ }
366
399
  }
367
400
  return result;
368
401
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.19.11",
3
+ "version": "3.20.0",
4
4
  "description": "SwaggerJS - a collection of interfaces for OAI specs",
5
5
  "browser": {
6
6
  "./src/http/fold-formdata-to-request.node.js": "./src/http/fold-formdata-to-request.browser.js",
@@ -84,8 +84,8 @@
84
84
  "cross-env": "=7.0.3",
85
85
  "eslint": "^8.42.0",
86
86
  "eslint-config-airbnb-base": "^15.0.0",
87
- "eslint-config-prettier": "=8.8.0",
88
- "eslint-plugin-import": "=2.27.5",
87
+ "eslint-config-prettier": "=8.9.0",
88
+ "eslint-plugin-import": "=2.28.0",
89
89
  "eslint-plugin-prettier": "=5.0.0",
90
90
  "expect": "^29.0.3",
91
91
  "fetch-mock": "=9.11.0",
@@ -106,7 +106,7 @@
106
106
  "rimraf": "=5.0.1",
107
107
  "source-map-explorer": "^2.5.3",
108
108
  "terser-webpack-plugin": "^5.0.3",
109
- "webpack": "=5.88.1",
109
+ "webpack": "=5.88.2",
110
110
  "webpack-bundle-size-analyzer": "=3.1.0",
111
111
  "webpack-cli": "=5.1.4",
112
112
  "webpack-stats-plugin": "=1.1.3",
@@ -114,10 +114,10 @@
114
114
  },
115
115
  "dependencies": {
116
116
  "@babel/runtime-corejs3": "^7.20.13",
117
- "@swagger-api/apidom-core": ">=0.71.0 <1.0.0",
118
- "@swagger-api/apidom-json-pointer": ">=0.71.0 <1.0.0",
119
- "@swagger-api/apidom-ns-openapi-3-1": ">=0.71.0 <1.0.0",
120
- "@swagger-api/apidom-reference": ">=0.71.1 <1.0.0",
117
+ "@swagger-api/apidom-core": ">=0.74.1 <1.0.0",
118
+ "@swagger-api/apidom-json-pointer": ">=0.74.1 <1.0.0",
119
+ "@swagger-api/apidom-ns-openapi-3-1": ">=0.74.1 <1.0.0",
120
+ "@swagger-api/apidom-reference": ">=0.74.1 <1.0.0",
121
121
  "cookie": "~0.5.0",
122
122
  "cross-fetch": "^3.1.5",
123
123
  "deepmerge": "~4.3.0",