swagger-api / swagger-api/swagger-codegen

[PYTHON] Content-Type should not be forced added to all requests

Open
#12,023 0 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

Generated python client seems to add Conten-Type: application/json to all requests, even though I don't have specify any content-type in the swagger declaration. This cause a problem to my server, because a GET request should not have Content-Type in the header.

Swagger-codegen version

3.0.36 (from Maven.org)

Swagger declaration file content or url

JSON file here

Command line used for generation
java -jar swagger-codegen-cli.jar generate -i building_resource_spec.json -o ./output_building -l python
Steps to reproduce

After the python clients are generated, check output_building/swagger_client/rest.py line 149. You can see that, the Content-Type is added to all requests.

        if 'Content-Type' not in headers:
            headers['Content-Type'] = 'application/json'
Suggest a fix/enhancement

I would expect at least that, the Content-Type is only added to PUT and PATCH requests

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

Reproduce the generation command and inspect output_building/swagger_client/rest.py at line 149, where Content-Type is added. Trace that generated code back to its Python client template and verify that the resulting client does not add Content-Type to GET requests when the Swagger declaration does not specify it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.