OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA/TYPESCRIPT] Invalid consumes headers generated

Open
#10,598 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When image/* is specified for requestBody content type, the generated spring server and typescript client (probably others as well) end up invalid.

On spring side:

    @RequestMapping(
        method = RequestMethod.POST,
        value = "/v1",
        consumes = { "image/_*" }
    )

On typescript side:

        // to determine the Content-Type header
        const consumes: string[] = [
            'image/_*'
        ];
openapi-generator version

5.2.1

OpenAPI declaration file content or url
{
  "paths": {
    "/v1": {
      "post": {
        "summary": "uploadImage",
        "operationId": "uploadImage",
        "requestBody": {
          "content": {
            "image/*": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}
Generation Details

Generator names were "spring" and "typescript-angular".

Suggest a fix

Tweak DefaultCodegen.addConsumesInfo.
Issue is with this line:

mediaType.put("mediaType", escapeText(escapeQuotationMark(key)));

The method escapeText is explicitly breaking /* and */.

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.

Research direction

Start with DefaultCodegen.addConsumesInfo and reproduce the issue using the provided OpenAPI declaration with the spring and typescript-angular generators. Check how the media type is escaped, then verify that generated consumes headers preserve image/* rather than producing image/_*.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, openapi, spring, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.