swagger-api / swagger-api/swagger-codegen

[JAVA] Content-Type in GET call

Open
#8,310 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The code generated for a GET API call looks like this:

final String[] localVarContentTypes = {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);

This leads to Content-Type: application/json in the header and an empty response from the server.

Swagger-codegen version

2.3.1, 3.0.0-rc1

Swagger declaration file content or url

https://my.sevdesk.de/swaggerJSON/swagger.json

The file contains

consumes": [
    "application/x-www-form-urlencoded"
],

for the call. I deleted the lines but still have the problem that a Content-Type is put to the header.

Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i var/sevdesk_swagger.json -l java -o var/java_api_client

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

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 the Java client generated by the supplied swagger-codegen command and inspect the GET method's header construction, especially selectHeaderContentType and the Content-Type assignment. Compare that output with the referenced Swagger declaration and its consumes value. Done means the generated GET call no longer sends an inappropriate Content-Type header and the affected response is returned correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.