OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] Not able to generate a `BlobApiResponse` with a binary response
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated apis/DefaultApi.ts output and the typescript-fetch template at modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache, especially the isResponseFile branch around line 341. Trace how the binary response schema is represented during generation and why isResponseFile is not enabled. Done means the sample spec generates runtime.BlobApiResponse instead of TextApiResponse.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100