Skip to content

typescript-angular2: Missing optional headers are sent as string 'undefined' #5638

@imgx64

Description

@imgx64
Description

When a header parameter is optional, and is not supplied when calling the API, the header is sent with the string undefined as its value.

Swagger-codegen version

swagger-codegen-cli 2.2.3-SNAPSHOT (downloaded from https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/2.2.3-SNAPSHOT/ )

Swagger declaration file content or url
swagger: '2.0'
info: 
  title: title
  version: "1"
paths:
  /:
    get:
      parameters:
        - name: "Accept-Language"
          in: "header"
          type: "string"
          required: false
      responses:
        200:
          description: ""
          
Command line used for generation
> java -jar ./swagger-codegen-cli-2.2.3-20170310.174729-1.jar generate -i swagger.yaml -l typ
escript-angular2 -o test
Steps to reproduce
  1. Generate the typescript-angular2 client as above.
  2. Import it into an Angular project.
  3. Call DefaultApi.rootGet().
  4. Notice the "Accept-Language: undefined" header in the sent request.
Related issues

Couldn't find any.

Suggest a Fix

This line is generated:

headers.set('Accept-Language', String(acceptLanguage));

It should check that the parameter exists before setting it. For example:

if (typeof acceptLanguage !== 'undefined') { // Or some other check, I'm not sure what is best
        headers.set('Accept-Language', String(acceptLanguage));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions