Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request: My company sponsors openapi-generator https://opencollective.com/itm
Description
Hello,
I'm currently trying to generate a typescript api client in which one endpoint should deliver a blob
as an API response. But no matter how I define the endpoint in my API spec, the client always tries to convert it to a string.
I followed the recommendation when modelling binary responses by using return type string
with format binary
but that doesn't work.
It will generate the correct return type for the methods:
Promise<runtime.ApiResponse<Blob>>
But it wrongly tries to convert the response to a text instead of a blob.
openapi-generator version
7.14.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Sample Attachment API
version: '1.0'
paths:
/attachment:
get:
operationId: getAttachment
responses:
default:
description: Attachment as binary data.
content:
application/octet-stream:
schema:
type: string
format: binary
Generation Details
java -jar openapi-generator-cli.jar generate -i api-docs/test-docs.yaml -g typescript-fetch -o src/test-api
Steps to reproduce
- generate
- look at
apis/DefaultApi.ts
if (this.isJsonMime(response.headers.get('content-type'))) {
return new runtime.JSONApiResponse<Blob>(response);
} else {
return new runtime.TextApiResponse(response) as any;
}
What should actually be generated is
return new runtime.BlobApiResponse(response);
Related issues/PRs
Suggest a fix
Looking at the template https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache#L341 I can see the function I need to be generated is already there - but I haven't found a way to trigger the isResponseFile
flag with my config.
Either I have a wrong api spec - in this case I would be very happy to be led in the right direction to fix it.
Or the generator has a bug in this case.