swagger-api / swagger-api/swagger-codegen

[JAVA] Content-Type is overwritten

Open
#4,978 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java General: Question
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

The Content-Type is always overwritten even if it has been supplied.

If a header parameter is described as follow

parameters:
    content-type:
        name: Content-Type
        in: header
        description: Content type
        type: string
        required: true

The client should be able to specify the content type of the request but this gets overwritten by the Java API. See https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache#L95

Maybe we should check if a Content-Type has already been supplied before overwriting assuming that if a client is supplying a Content-Type he knows what he is doing.

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

Inspect modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache around line 95, where the Content-Type is overwritten. Reproduce the case with a supplied Content-Type header and confirm that the generated Java client preserves it; done means generated requests retain the caller-provided value instead of replacing it.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.