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..b49026b8991 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']; @@ -21,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 = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); {{#hasFormParams}} let formParams: any = {}; @@ -42,7 +50,6 @@ namespace {{package}} { if (!{{paramName}}) { throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); } - {{/required}} {{/allParams}} {{#queryParams}} @@ -76,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);