forked from loafle/openapi-generator-original
[JS] (#7913) Adding support for multi file upload. Also adding the option for individual CodeGens to specify a collectionFormat (#7914)
* updated samples as well
This commit is contained in:
@@ -280,6 +280,8 @@ class ApiClient {
|
||||
case 'multi':
|
||||
//return the array directly as SuperAgent will handle it as expected
|
||||
return param.map(this.paramToString, this);
|
||||
case 'passthrough':
|
||||
return param;
|
||||
default:
|
||||
throw new Error('Unknown collection format: ' + collectionFormat);
|
||||
}
|
||||
@@ -439,11 +441,16 @@ class ApiClient {
|
||||
var _formParams = this.normalizeParams(formParams);
|
||||
for (var key in _formParams) {
|
||||
if (_formParams.hasOwnProperty(key)) {
|
||||
if (this.isFileParam(_formParams[key])) {
|
||||
let _formParamsValue = _formParams[key];
|
||||
if (this.isFileParam(_formParamsValue)) {
|
||||
// file field
|
||||
request.attach(key, _formParams[key]);
|
||||
request.attach(key, _formParamsValue);
|
||||
} else if (Array.isArray(_formParamsValue) && _formParamsValue.length
|
||||
&& this.isFileParam(_formParamsValue[0])) {
|
||||
// multiple files
|
||||
_formParamsValue.forEach(file => request.attach(key, file));
|
||||
} else {
|
||||
request.field(key, _formParams[key]);
|
||||
request.field(key, _formParamsValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user