1
1
{ {> licenseInfo} }
2
2
/* tslint:disable:no-unused-variable member-ordering */
3
3
4
- import { Observable } from " rxjs/Observable" ;
4
+ import { Observable } from ' rxjs/Observable' ;
5
5
import 'rxjs/add/operator/map';
6
6
import 'rxjs/add/operator/toPromise';
7
- import IHttpClient from " ../IHttpClient" ;
8
- import { inject, injectable } from " inversify" ;
9
- import { IAPIConfiguration } from " ../IAPIConfiguration" ;
10
- import { Headers } from " ../Headers" ;
11
- import HttpResponse from " ../HttpResponse" ;
7
+ import IHttpClient from ' ../IHttpClient' ;
8
+ import { inject, injectable } from ' inversify' ;
9
+ import { IAPIConfiguration } from ' ../IAPIConfiguration' ;
10
+ import { Headers } from ' ../Headers' ;
11
+ import HttpResponse from ' ../HttpResponse' ;
12
12
13
13
{ {#imports} }
14
14
import { {{classname} } } from '../{ {filename} }';
@@ -34,13 +34,10 @@ export class {{classname}} implements {{classname}}Interface {
34
34
{ {^withInterfaces} }
35
35
export class { {classname} } {
36
36
{{/withInterfaces} }
37
- private basePath: string = '{ {{basePath} }}';
37
+ @inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration;
38
+ @inject('IApiHttpClient') private httpClient: IHttpClient;
39
+
38
40
39
- constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
40
- @inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
41
- if (this.APIConfiguration.basePath)
42
- this.basePath = this.APIConfiguration.basePath;
43
- }
44
41
{ {#operation} }
45
42
46
43
/**
@@ -68,21 +65,21 @@ export class {{classname}} {
68
65
if ({ {paramName} }) {
69
66
{{#isCollectionFormatMulti} }
70
67
{ {paramName} }.forEach((element) => {
71
- queryParameters.push(" {{paramName}}=" +encodeURIComponent(String({{paramName} })));
68
+ queryParameters.push(' {{paramName}}=' +encodeURIComponent(String({{paramName} })));
72
69
})
73
70
{ {/isCollectionFormatMulti} }
74
71
{ {^isCollectionFormatMulti} }
75
- queryParameters.push(" { {paramName} }=" +encodeURIComponent({ {paramName} }.join(COLLECTION_FORMATS['{ {collectionFormat} }'])));
72
+ queryParameters.push(' { {paramName} }=' +encodeURIComponent({ {paramName} }.join(COLLECTION_FORMATS['{ {collectionFormat} }'])));
76
73
{ {/isCollectionFormatMulti} }
77
74
}
78
75
{ {/isListContainer} }
79
76
{ {^isListContainer} }
80
77
if ({ {paramName} } !== undefined) {
81
78
{{#isDateTime} }
82
- queryParameters.push(" { {paramName} }=" +encodeURIComponent(<any >{ {paramName} }.toISOString()));
79
+ queryParameters.push(' { {paramName} }=' +encodeURIComponent(<any >{ {paramName} }.toISOString()));
83
80
{ {/isDateTime} }
84
81
{ {^isDateTime} }
85
- queryParameters.push(" { {paramName} }=" +encodeURIComponent(String({ {paramName} })));
82
+ queryParameters.push(' { {paramName} }=' +encodeURIComponent(String({ {paramName} })));
86
83
{ {/isDateTime} }
87
84
}
88
85
{ {/isListContainer} }
@@ -106,13 +103,13 @@ export class {{classname}} {
106
103
// authentication ({ {name} }) required
107
104
{ {#isApiKey} }
108
105
{ {#isKeyInHeader} }
109
- if (this.APIConfiguration.apiKeys[" { {keyParamName} }" ]) {
110
- headers[' {{keyParamName}}' ] = this.APIConfiguration.apiKeys[" {{keyParamName}}" ];
106
+ if (this.APIConfiguration.apiKeys[' { {keyParamName} }' ]) {
107
+ headers[' {{keyParamName}}' ] = this.APIConfiguration.apiKeys[' {{keyParamName}}' ];
111
108
}
112
109
{ {/isKeyInHeader} }
113
110
{ {#isKeyInQuery} }
114
- if (this.APIConfiguration.apiKeys[" { {keyParamName} }" ]) {
115
- queryParameters.push(" {{paramName}}=" +encodeURIComponent(String(this.APIConfiguration.apiKeys[" {{keyParamName}}" ])));
111
+ if (this.APIConfiguration.apiKeys[' { {keyParamName} }' ]) {
112
+ queryParameters.push(' {{paramName}}=' +encodeURIComponent(String(this.APIConfiguration.apiKeys[' {{keyParamName}}' ])));
116
113
}
117
114
{ {/isKeyInQuery} }
118
115
{ {/isApiKey} }
@@ -169,9 +166,9 @@ export class {{classname}} {
169
166
{ {/formParams} }
170
167
171
168
{ {/hasFormParams} }
172
- const response: Observable<HttpResponse <{ { #returnType} } { { { returnType} } } { { #isResponseTypeFile} } |undefined{{ /isResponseTypeFile}}{{ /returnType}}{{^returnType}}any{{ /returnType}} >> = this.httpClient.{ {httpMethod} }(`${ this.basePath} { {{path} }}{ {#hasQueryParams} }?${ queryParameters.join(' &' )} { {/hasQueryParams} }`{ {#bodyParam} }, { {paramName} } { {/bodyParam} }{ {#hasFormParams} }, body{ {/hasFormParams} }, headers);
173
- if (observe == 'body') {
174
- return response.map(httpResponse => < {{#returnType } } { {{returnType } }} { {#isResponseTypeFile } }|undefined { {/isResponseTypeFile } } { {/returnType } } { {^returnType } }any { {/returnType } }>( httpResponse.response) ){ {#usePromise} }.toPromise(){ {/usePromise} };
169
+ const response: Observable<HttpResponse <{ { #returnType} } { { { returnType} } } { { #isResponseTypeFile} } |undefined{{ /isResponseTypeFile}}{{ /returnType}}{{^returnType}}any{{ /returnType}} >> = this.httpClient.{ {httpMethod} }(`${ this.APIConfiguration. basePath} { {{path} }}{ {#hasQueryParams} }?${ queryParameters.join(' &' )} { {/hasQueryParams} }`{ {#bodyParam} }, { {paramName} }{ {/bodyParam} } as any { {#hasFormParams} }, body{ {/hasFormParams} }, headers);
170
+ if (observe === 'body') {
171
+ return response.map(httpResponse => httpResponse.response){{#usePromise} }.toPromise(){ {/usePromise} };
175
172
}
176
173
return response{ {#usePromise} }.toPromise(){ {/usePromise} };
177
174
}
0 commit comments