[BUG] [JS] “this” is undefined inside map function
Created by: tray2100
Description
There depending on how a method is called, this
may be undefined. This specifically happens when buildCollectionParam is called statically instead of from an instance.
Based on the Array.prototype.map() spec we can/should pass this
as an arg to avoid this issue.
openapi-generator version
4.3.1 ... doesn't look to be a regression. Just missing handling
Suggest a fix
switch (collectionFormat) {
case 'csv':
return param.map(this.paramToString, this).join(',');
case 'ssv':
return param.map(this.paramToString, this).join(' ');
case 'tsv':
return param.map(this.paramToString, this).join('\t');
case 'pipes':
return param.map(this.paramToString, this).join('|');
case 'multi':
// return the array directly as SuperAgent will handle it as expected
return param.map(this.paramToString, this);
default:
throw new Error('Unknown collection format: ' + collectionFormat);