mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
Merge pull request #1486 from aersamkull/master
Addes default headers for TypeScript Angular
This commit is contained in:
commit
1f38ce724f
@ -13,6 +13,7 @@ namespace {{package}} {
|
|||||||
{{/description}}
|
{{/description}}
|
||||||
export class {{classname}} {
|
export class {{classname}} {
|
||||||
private basePath = '{{basePath}}';
|
private basePath = '{{basePath}}';
|
||||||
|
public defaultHeaders : any = {};
|
||||||
|
|
||||||
static $inject: string[] = ['$http', '$httpParamSerializer'];
|
static $inject: string[] = ['$http', '$httpParamSerializer'];
|
||||||
|
|
||||||
@ -21,17 +22,24 @@ namespace {{package}} {
|
|||||||
this.basePath = basePath;
|
this.basePath = basePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}}
|
{{#operation}}
|
||||||
|
|
||||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
|
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 queryParameters: any = {};
|
||||||
let headerParams: any = {};
|
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||||
{{#hasFormParams}}
|
{{#hasFormParams}}
|
||||||
let formParams: any = {};
|
let formParams: any = {};
|
||||||
|
|
||||||
@ -42,7 +50,6 @@ namespace {{package}} {
|
|||||||
if (!{{paramName}}) {
|
if (!{{paramName}}) {
|
||||||
throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
|
throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
{{#queryParams}}
|
{{#queryParams}}
|
||||||
@ -76,11 +83,7 @@ namespace {{package}} {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (extraHttpRequestParams) {
|
if (extraHttpRequestParams) {
|
||||||
for (let k in extraHttpRequestParams) {
|
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
|
||||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.$http(httpRequestParams);
|
return this.$http(httpRequestParams);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user