Skip to content

Commit 55443da

Browse files
damienpontifexwing328
authored andcommitted
Extends obj using Object.assign (#4562)
1 parent 545ee0c commit 55443da

File tree

17 files changed

+161
-419
lines changed

17 files changed

+161
-419
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ namespace {{package}} {
2424
}
2525
}
2626

27-
private extendObj<T1,T2>(objA: T1, objB: T2) {
28-
for(let key in objB){
29-
if(objB.hasOwnProperty(key)){
30-
objA[key] = objB[key];
31-
}
32-
}
33-
return <T1&T2>objA;
34-
}
35-
3627
{{#operation}}
3728
/**
3829
* {{summary}}
@@ -44,7 +35,7 @@ namespace {{package}} {
4435
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
4536

4637
let queryParameters: any = {};
47-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
38+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
4839
{{#hasFormParams}}
4940
let formParams: any = {};
5041

@@ -75,10 +66,9 @@ namespace {{package}} {
7566
formParams['{{baseName}}'] = {{paramName}};
7667

7768
{{/formParams}}
78-
let httpRequestParams: any = {
69+
let httpRequestParams: ng.IRequestConfig = {
7970
method: '{{httpMethod}}',
8071
url: localVarPath,
81-
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
8272
{{#bodyParam}}data: {{paramName}},
8373
{{/bodyParam}}
8474
{{#hasFormParams}}data: this.$httpParamSerializer(formParams),
@@ -88,7 +78,7 @@ namespace {{package}} {
8878
};
8979

9080
if (extraHttpRequestParams) {
91-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
81+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
9282
}
9383

9484
return this.$http(httpRequestParams);

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ export class {{classname}} {
3535
}
3636
}
3737

38-
/**
39-
*
40-
* Extends object by coping non-existing properties.
41-
* @param objA object to be extended
42-
* @param objB source object
43-
*/
44-
private extendObj<T1,T2>(objA: T1, objB: T2) {
45-
for(let key in objB){
46-
if(objB.hasOwnProperty(key)){
47-
(objA as any)[key] = (objB as any)[key];
48-
}
49-
}
50-
return <T1&T2>objA;
51-
}
52-
5338
{{#operation}}
5439
/**
5540
* {{summary}}
@@ -213,7 +198,7 @@ export class {{classname}} {
213198

214199
// https://github.com/swagger-api/swagger-codegen/issues/4037
215200
if (extraHttpRequestParams) {
216-
requestOptions = this.extendObj(requestOptions, extraHttpRequestParams);
201+
requestOptions = (<any>Object).assign(requestOptions, extraHttpRequestParams);
217202
}
218203

219204
return this.http.request(path, requestOptions);

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,6 @@ export class {{classname}} {
183183
}
184184
{{/isOAuth}}
185185
{{/authMethods}}
186-
private extendObj<T1,T2>(objA: T1, objB: T2) {
187-
for(let key in objB){
188-
if(objB.hasOwnProperty(key)){
189-
objA[key] = objB[key];
190-
}
191-
}
192-
return <T1&T2>objA;
193-
}
194186
{{#operation}}
195187
/**
196188
* {{summary}}
@@ -201,7 +193,7 @@ export class {{classname}} {
201193
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
202194
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
203195
let queryParameters: any = {};
204-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
196+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
205197
let formParams: any = {};
206198

207199
{{#allParams}}{{#required}}

samples/client/petstore/typescript-angular/API/Client/PetApi.ts

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ namespace API.Client {
2929
}
3030
}
3131

32-
private extendObj<T1,T2>(objA: T1, objB: T2) {
33-
for(let key in objB){
34-
if(objB.hasOwnProperty(key)){
35-
objA[key] = objB[key];
36-
}
37-
}
38-
return <T1&T2>objA;
39-
}
40-
4132
/**
4233
* Add a new pet to the store
4334
*
@@ -47,18 +38,17 @@ namespace API.Client {
4738
const localVarPath = this.basePath + '/pet';
4839

4940
let queryParameters: any = {};
50-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
51-
let httpRequestParams: any = {
41+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
42+
let httpRequestParams: ng.IRequestConfig = {
5243
method: 'POST',
5344
url: localVarPath,
54-
json: true,
5545
data: body,
5646
params: queryParameters,
5747
headers: headerParams
5848
};
5949

6050
if (extraHttpRequestParams) {
61-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
51+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
6252
}
6353

6454
return this.$http(httpRequestParams);
@@ -74,23 +64,22 @@ namespace API.Client {
7464
.replace('{' + 'petId' + '}', String(petId));
7565

7666
let queryParameters: any = {};
77-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
67+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
7868
// verify required parameter 'petId' is not null or undefined
7969
if (petId === null || petId === undefined) {
8070
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
8171
}
8272
headerParams['api_key'] = apiKey;
8373

84-
let httpRequestParams: any = {
74+
let httpRequestParams: ng.IRequestConfig = {
8575
method: 'DELETE',
8676
url: localVarPath,
87-
json: true,
8877
params: queryParameters,
8978
headers: headerParams
9079
};
9180

9281
if (extraHttpRequestParams) {
93-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
82+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
9483
}
9584

9685
return this.$http(httpRequestParams);
@@ -104,21 +93,20 @@ namespace API.Client {
10493
const localVarPath = this.basePath + '/pet/findByStatus';
10594

10695
let queryParameters: any = {};
107-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
96+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
10897
if (status !== undefined) {
10998
queryParameters['status'] = status;
11099
}
111100

112-
let httpRequestParams: any = {
101+
let httpRequestParams: ng.IRequestConfig = {
113102
method: 'GET',
114103
url: localVarPath,
115-
json: true,
116104
params: queryParameters,
117105
headers: headerParams
118106
};
119107

120108
if (extraHttpRequestParams) {
121-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
109+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
122110
}
123111

124112
return this.$http(httpRequestParams);
@@ -132,21 +120,20 @@ namespace API.Client {
132120
const localVarPath = this.basePath + '/pet/findByTags';
133121

134122
let queryParameters: any = {};
135-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
123+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
136124
if (tags !== undefined) {
137125
queryParameters['tags'] = tags;
138126
}
139127

140-
let httpRequestParams: any = {
128+
let httpRequestParams: ng.IRequestConfig = {
141129
method: 'GET',
142130
url: localVarPath,
143-
json: true,
144131
params: queryParameters,
145132
headers: headerParams
146133
};
147134

148135
if (extraHttpRequestParams) {
149-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
136+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
150137
}
151138

152139
return this.$http(httpRequestParams);
@@ -161,21 +148,20 @@ namespace API.Client {
161148
.replace('{' + 'petId' + '}', String(petId));
162149

163150
let queryParameters: any = {};
164-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
151+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
165152
// verify required parameter 'petId' is not null or undefined
166153
if (petId === null || petId === undefined) {
167154
throw new Error('Required parameter petId was null or undefined when calling getPetById.');
168155
}
169-
let httpRequestParams: any = {
156+
let httpRequestParams: ng.IRequestConfig = {
170157
method: 'GET',
171158
url: localVarPath,
172-
json: true,
173159
params: queryParameters,
174160
headers: headerParams
175161
};
176162

177163
if (extraHttpRequestParams) {
178-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
164+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
179165
}
180166

181167
return this.$http(httpRequestParams);
@@ -189,18 +175,17 @@ namespace API.Client {
189175
const localVarPath = this.basePath + '/pet';
190176

191177
let queryParameters: any = {};
192-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
193-
let httpRequestParams: any = {
178+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
179+
let httpRequestParams: ng.IRequestConfig = {
194180
method: 'PUT',
195181
url: localVarPath,
196-
json: true,
197182
data: body,
198183
params: queryParameters,
199184
headers: headerParams
200185
};
201186

202187
if (extraHttpRequestParams) {
203-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
188+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
204189
}
205190

206191
return this.$http(httpRequestParams);
@@ -217,7 +202,7 @@ namespace API.Client {
217202
.replace('{' + 'petId' + '}', String(petId));
218203

219204
let queryParameters: any = {};
220-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
205+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
221206
let formParams: any = {};
222207

223208
// verify required parameter 'petId' is not null or undefined
@@ -230,17 +215,16 @@ namespace API.Client {
230215

231216
formParams['status'] = status;
232217

233-
let httpRequestParams: any = {
218+
let httpRequestParams: ng.IRequestConfig = {
234219
method: 'POST',
235220
url: localVarPath,
236-
json: false,
237221
data: this.$httpParamSerializer(formParams),
238222
params: queryParameters,
239223
headers: headerParams
240224
};
241225

242226
if (extraHttpRequestParams) {
243-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
227+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
244228
}
245229

246230
return this.$http(httpRequestParams);
@@ -257,7 +241,7 @@ namespace API.Client {
257241
.replace('{' + 'petId' + '}', String(petId));
258242

259243
let queryParameters: any = {};
260-
let headerParams: any = this.extendObj({}, this.defaultHeaders);
244+
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
261245
let formParams: any = {};
262246

263247
// verify required parameter 'petId' is not null or undefined
@@ -270,17 +254,16 @@ namespace API.Client {
270254

271255
formParams['file'] = file;
272256

273-
let httpRequestParams: any = {
257+
let httpRequestParams: ng.IRequestConfig = {
274258
method: 'POST',
275259
url: localVarPath,
276-
json: false,
277260
data: this.$httpParamSerializer(formParams),
278261
params: queryParameters,
279262
headers: headerParams
280263
};
281264

282265
if (extraHttpRequestParams) {
283-
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
266+
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
284267
}
285268

286269
return this.$http(httpRequestParams);

0 commit comments

Comments
 (0)