Swagger-codegen: [Typescript-angular] responseType not set on Blob type responses

Created on 7 Nov 2019  路  2Comments  路  Source: swagger-api/swagger-codegen

Description

If response is a blob (in schema defined with type string, format binary), the generated service fails to consume renspose (it tries to parse binary repsonse as blob):
typescript return this.httpClient.get<Blob>(`${this.basePath}/api/Image/DesignPreview`, { params: queryParameters, withCredentials: this.configuration.withCredentials, headers: headers, observe: observe, reportProgress: reportProgress } );

Swagger-codegen version

We are transitioning to aspnetcore3, with that we need to transition to swagger-codegen-cli-3.0.13
This issue did not exist in cli-2.4.1-SNAPSHOT with schema v2

Swagger declaration file content or url

Relevant schema part:
json "responses": { "200": { "description": "Success", "content": { "image/png": { "schema": { "type": "string", "format": "binary" } } } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" } },

Command line used for generation

java -jar swagger/swagger-codegen-cli-3.0.13.jar generate -i https://localhost:5001/swagger/0.1-Dev/swagger.json -l typescript-angular -c swagger/config.json -o src/app/api -D io.swagger.parser.util.RemoteUrl.trustAll=true -D io.swagger.v3.parser.util.RemoteUrl.trustAll=true

config.json:
json { "ngVersion":"8" }

Related issues/PRs

Very similar issue to #8399

Suggest a fix/enhancement

responseType: 'blob' and non generic httpClient.get should be used

Most helpful comment

same for type=file,
this.httpClient.request<Blob> should be this.httpClient.request (remove the generic parameter)

and the options should add responseType: 'blob'

All 2 comments

same for type=file,
this.httpClient.request<Blob> should be this.httpClient.request (remove the generic parameter)

and the options should add responseType: 'blob'

Also having this issue, it would be nice if it could be addressed soon

Was this page helpful?
0 / 5 - 0 ratings