Skip to content

[TS][Angular1&2][Node] Extends obj using Object.assign #4562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace {{package}} {
}
}

private extendObj<T1,T2>(objA: T1, objB: T2) {
for(let key in objB){
if(objB.hasOwnProperty(key)){
objA[key] = objB[key];
}
}
return <T1&T2>objA;
}

{{#operation}}
/**
* {{summary}}
Expand All @@ -44,7 +35,7 @@ namespace {{package}} {
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
{{#hasFormParams}}
let formParams: any = {};

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

{{/formParams}}
let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: '{{httpMethod}}',
url: localVarPath,
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
{{#bodyParam}}data: {{paramName}},
{{/bodyParam}}
{{#hasFormParams}}data: this.$httpParamSerializer(formParams),
Expand All @@ -88,7 +78,7 @@ namespace {{package}} {
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

return this.$http(httpRequestParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ export class {{classname}} {
}
}

/**
*
* Extends object by coping non-existing properties.
* @param objA object to be extended
* @param objB source object
*/
private extendObj<T1,T2>(objA: T1, objB: T2) {
for(let key in objB){
if(objB.hasOwnProperty(key)){
(objA as any)[key] = (objB as any)[key];
}
}
return <T1&T2>objA;
}

{{#operation}}
/**
* {{summary}}
Expand Down Expand Up @@ -213,7 +198,7 @@ export class {{classname}} {

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

return this.http.request(path, requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ export class {{classname}} {
}
{{/isOAuth}}
{{/authMethods}}
private extendObj<T1,T2>(objA: T1, objB: T2) {
for(let key in objB){
if(objB.hasOwnProperty(key)){
objA[key] = objB[key];
}
}
return <T1&T2>objA;
}
{{#operation}}
/**
* {{summary}}
Expand All @@ -201,7 +193,7 @@ export class {{classname}} {
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let formParams: any = {};

{{#allParams}}{{#required}}
Expand Down
65 changes: 24 additions & 41 deletions samples/client/petstore/typescript-angular/API/Client/PetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ namespace API.Client {
}
}

private extendObj<T1,T2>(objA: T1, objB: T2) {
for(let key in objB){
if(objB.hasOwnProperty(key)){
objA[key] = objB[key];
}
}
return <T1&T2>objA;
}

/**
* Add a new pet to the store
*
Expand All @@ -47,18 +38,17 @@ namespace API.Client {
const localVarPath = this.basePath + '/pet';

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
json: true,
data: body,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

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

let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'DELETE',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
if (status !== undefined) {
queryParameters['status'] = status;
}

let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
if (tags !== undefined) {
queryParameters['tags'] = tags;
}

let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling getPetById.');
}
let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let httpRequestParams: ng.IRequestConfig = {
method: 'PUT',
url: localVarPath,
json: true,
data: body,
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let formParams: any = {};

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

formParams['status'] = status;

let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

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

let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let formParams: any = {};

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

formParams['file'] = file;

let httpRequestParams: any = {
let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
params: queryParameters,
headers: headerParams
};

if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
httpRequestParams = (<any>Object).assign(httpRequestParams, extraHttpRequestParams);
}

return this.$http(httpRequestParams);
Expand Down
Loading