-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Milestone
Description
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
- Generate the typescript-angular2 client as above.
- Import it into an Angular project.
- Call
DefaultApi.rootGet()
. - 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));
}