From 943f8606caa69574537b8132c989b934bd1ad25f Mon Sep 17 00:00:00 2001 From: stevedenman Date: Fri, 9 Sep 2016 12:51:48 +1200 Subject: [PATCH 1/3] Add last response code and headers Apply same workaround as https://github.com/swagger-api/swagger-codegen/pull/1127 to typescript-angular2 template. --- .../resources/typescript-angular2/api.mustache | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index f033a8a4b6c..1ec7d1c081f 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -24,6 +24,17 @@ export class {{classname}} { protected basePath = '{{basePath}}'; public defaultHeaders: Headers = new Headers(); + private _statusCode: number; + private _responseHeaders: Headers; + + public get statusCode (): number { + return this._statusCode; + } + + public get responseHeaders (): Headers { + return this._responseHeaders; + } + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string) { if (basePath) { this.basePath = basePath; @@ -107,6 +118,10 @@ export class {{classname}} { return this.http.request(path, requestOptions) .map((response: Response) => { + + this._statusCode = response.status; + this._responseHeaders = response.headers; + if (response.status === 204) { return undefined; } else { @@ -117,4 +132,4 @@ export class {{classname}} { {{/operation}} } -{{/operations}} \ No newline at end of file +{{/operations}} From 9f787571183bb3f6752228e55793a5106a88844b Mon Sep 17 00:00:00 2001 From: Steve Denman Date: Fri, 9 Sep 2016 20:39:47 +1200 Subject: [PATCH 2/3] Add WithHttpInfo() methods to return raw response. --- .../typescript-angular2/api.mustache | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index 1ec7d1c081f..b7f6b11851d 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -24,17 +24,6 @@ export class {{classname}} { protected basePath = '{{basePath}}'; public defaultHeaders: Headers = new Headers(); - private _statusCode: number; - private _responseHeaders: Headers; - - public get statusCode (): number { - return this._statusCode; - } - - public get responseHeaders (): Headers { - return this._responseHeaders; - } - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string) { if (basePath) { this.basePath = basePath; @@ -48,6 +37,25 @@ export class {{classname}} { {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { + return this.{{nickname}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json(); + } + }); + } + +{{/operation}} + +{{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}}*/ + public {{nickname}}WithHttpInfo({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable { const path = this.basePath + `{{path}}`; let queryParameters = new URLSearchParams(); @@ -104,7 +112,7 @@ export class {{classname}} { {{/formParams}} let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: {{httpMethod}}, + method: '{{httpMethod}}', headers: headers, {{#bodyParam}} body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612 @@ -116,20 +124,9 @@ export class {{classname}} { responseType: ResponseContentType.Json }); - return this.http.request(path, requestOptions) - .map((response: Response) => { - - this._statusCode = response.status; - this._responseHeaders = response.headers; - - if (response.status === 204) { - return undefined; - } else { - return response.json(); - } - }); + return this.http.request(path, requestOptions); } {{/operation}} } -{{/operations}} +{{/operations}} \ No newline at end of file From 2328f407829e29c50dfbd4ebb99ae0c3f5c10009 Mon Sep 17 00:00:00 2001 From: Steve Denman Date: Fri, 9 Sep 2016 21:15:27 +1200 Subject: [PATCH 3/3] Revert change to http method formatting --- .../src/main/resources/typescript-angular2/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index b7f6b11851d..33f6fab75c0 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -112,7 +112,7 @@ export class {{classname}} { {{/formParams}} let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: '{{httpMethod}}', + method: {{httpMethod}}, headers: headers, {{#bodyParam}} body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612