swagger-api/swagger-codegen-generators

[Typescript angular] responseType blob not set properly

luca-vercelli opened this issue · 0 comments

I have a GET endpoint that downloads a file:

  responses:
    '200':
      description: OK
      content:
        application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
          schema:
            type: string
            format: binary

Generated typescript code is

    (...)
    return this.httpClient.request<any>('get',`${this.basePath}/mypath`,
        {
            params: queryParameters,
            withCredentials: this.configuration.withCredentials,
            headers: headers,
            observe: observe,
            reportProgress: reportProgress
        }
    );

while it should contain a responseType:

    (...)
    return this.httpClient.request('get',`${this.basePath}/mypath`,
        {
            params: queryParameters,
            responseType: "blob",
            withCredentials: this.configuration.withCredentials,
            headers: headers,
            observe: observe,
            reportProgress: reportProgress
        }

Thanks to stackoverflow we can get the desired result setting a x-is-file option:

  responses:
    '200':
      description: OK
      x-is-file: true
      content:
        application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
          schema:
            type: string
            format: binary

However of course this is a workaround, x-is-file is an internal option, it is not part of OpenAPI standard.

I think there is a bug around this point of code:

codegenResponse.getVendorExtensions().put(CodegenConstants.IS_FILE_EXT_NAME, Boolean.TRUE);

This line is not executed.