Skip to content

[BUG] [JS] “this” is undefined inside map function  #7910

@tray2100

Description

@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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions