OpenAPITools / OpenAPITools/openapi-generator
[BUG] parsing application/problem+json when use typescript generated PromiseApis
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
openapi-generator version
2.3.3
OpenAPI declaration file content or url
any http response with content-type application/problem+json
Generation Details
models/ObjectSerializer.ts
/**
* Convert data to a string according the given media type
*/
public static stringify(data: any, mediaType: string): string {
if (mediaType === "application/json") {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
Steps to reproduce
call generated PromiseApi and server send http response with content-type application/problem+json not application/json.
will call ObjectSerializer.stringify() with application/problem+json internally, throw not supported mediaType error
Related issues/PRs
I searched with "problem+json" keyword, but can't find any similar issue. sorry.
https://github.com/OpenAPITools/openapi-generator/pulls?q=%22problem%2Bjson%22+
Suggest a fix
- if (mediaType === "application/json") {
+ if (mediaType === "application/json" || mediaType === "application/problem+json") {
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 at modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache, especially ObjectSerializer.stringify, and trace how generated PromiseApis handle a response with application/problem+json. Reproduce the unsupported media type error described in the issue, then verify that generated TypeScript clients accept this content type without throwing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100