Skip to content

Commit ad0838f

Browse files
taxponwing328
authored andcommitted
[ts-ng2] add check whether header parameter is undefined or not (#5668)
1 parent bc34062 commit ad0838f

File tree

8 files changed

+14
-5
lines changed

8 files changed

+14
-5
lines changed

modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ export class {{classname}} {
115115
}
116116
{{/isListContainer}}
117117
{{^isListContainer}}
118-
headers.set('{{baseName}}', String({{paramName}}));
118+
if ({{paramName}} !== undefined && {{paramName}} !== null) {
119+
headers.set('{{baseName}}', String({{paramName}}));
120+
}
119121
{{/isListContainer}}
120122

121123
{{/headerParams}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.3-SNAPSHOT

samples/client/petstore-security-test/typescript-angular2/api/FakeApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class FakeApi {
5151
if (response.status === 204) {
5252
return undefined;
5353
} else {
54-
return response.json();
54+
return response.json() || {};
5555
}
5656
});
5757
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.3-SNAPSHOT

samples/client/petstore/typescript-angular2/default/api/PetApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ export class PetApi {
242242
if (petId === null || petId === undefined) {
243243
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
244244
}
245-
headers.set('api_key', String(apiKey));
245+
if (apiKey !== undefined && apiKey !== null) {
246+
headers.set('api_key', String(apiKey));
247+
}
246248

247249
// to determine the Content-Type header
248250
let consumes: string[] = [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.3-SNAPSHOT

samples/client/petstore/typescript-angular2/npm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ import { BASE_PATH } from './path-to-swagger-gen-service/index';
4141
bootstrap(AppComponent, [
4242
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
4343
]);
44-
```
44+
```

samples/client/petstore/typescript-angular2/npm/api/PetApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ export class PetApi {
242242
if (petId === null || petId === undefined) {
243243
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
244244
}
245-
headers.set('api_key', String(apiKey));
245+
if (apiKey !== undefined && apiKey !== null) {
246+
headers.set('api_key', String(apiKey));
247+
}
246248

247249
// to determine the Content-Type header
248250
let consumes: string[] = [

0 commit comments

Comments
 (0)