OpenAPITools / OpenAPITools/openapi-generator
Generated TypeScript-Code calls the HttpClient with ResponseType 'blob' by default (instead of 'json')
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 (example)?
- 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 (example)
Description
If the consumer does not explicitly define the content type (in Java con consumes = MediaType.APPLICATION_JSON_VALUE) then the generated TypeScript code is like
public saveOrder(orderId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: '*/*', context?: HttpContext}): Observable<Angebot>;
Important is httpHeaderAccept?: '*/*',
This leads to the fact that in the following generated lines
let responseType_: 'text' | 'json' | 'blob' = 'json';
if (localVarHttpHeaderAcceptSelected) {
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
responseType_ = 'json';
} else {
responseType_ = 'blob';
}
}
the responseType is set to 'blob'. I don't think that was intended.
openapi-generator version
This Bug exists since version 5.4.0.
Suggest a fix
Consider also the case */* in the code above.
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 by locating the TypeScript generator code or template that emits the shown responseType_ selection, then trace how an Accept value of / is handled. Verify the generated client uses 'json' rather than 'blob' when the operation has no explicit content type, and add or update the relevant generator test if one exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100