From 2b24aa8f915a5040d528914d4f51cf87a87866b7 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Thu, 29 Oct 2015 09:15:18 +0100 Subject: [PATCH 1/2] adds default headers --- .../src/main/resources/TypeScript-Angular/api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 9681634a765..18c325fa422 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -13,6 +13,7 @@ namespace {{package}} { {{/description}} export class {{classname}} { private basePath = '{{basePath}}'; + public defaultHeaders : any = {}; static $inject: string[] = ['$http', '$httpParamSerializer']; @@ -31,7 +32,7 @@ namespace {{package}} { {{/pathParams}} let queryParameters: any = {}; - let headerParams: any = {}; + let headerParams: any = this.defaultHeaders; {{#hasFormParams}} let formParams: any = {}; From 3762ea472d01902441d31105f4e541f1facb98f5 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Mon, 2 Nov 2015 08:28:46 +0100 Subject: [PATCH 2/2] Adds default headers --- .../resources/TypeScript-Angular/api.mustache | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 18c325fa422..b49026b8991 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -22,17 +22,24 @@ namespace {{package}} { this.basePath = basePath; } } + + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + {{#operation}} public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { - let path = this.basePath + '{{path}}'; + const path = this.basePath + '{{path}}'{{#pathParams}} + .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; -{{#pathParams}} - path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}})); - -{{/pathParams}} let queryParameters: any = {}; - let headerParams: any = this.defaultHeaders; + let headerParams: any = this.extendObj({}, this.defaultHeaders); {{#hasFormParams}} let formParams: any = {}; @@ -43,7 +50,6 @@ namespace {{package}} { if (!{{paramName}}) { throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); } - {{/required}} {{/allParams}} {{#queryParams}} @@ -77,11 +83,7 @@ namespace {{package}} { }; if (extraHttpRequestParams) { - for (let k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams);