[BUG] parsing application/problem+json when use typescript generated PromiseApis

Open Beginner friendly
#11,099 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
api

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.

Description

Issue: Bug
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

https://github.com/OpenAPITools/openapi-generator/blob/fbb61658dfbcc2c1f5087511b0f74756553791ad/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache#L229

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") {
Dominant language
Java
Stars
26.8k
Forks
7.7k
Avg merge
1d 10h
Merged PRs (30d)
103

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.