swagger-api / swagger-api/swagger-codegen

[PYTHON] Bug: client applies Content-Type header when no request body is present

Open
#10,378 1 comment 0 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

Requests with no body parameters (ie, no request body) should not include a Content-Type header.
This was acknowledged to be a bug for the Java Feign client (see #6647), and was fixed. I'm asking for parity in the Python client.

Swagger-codegen version

2.3.0

Swagger declaration file content or url
swagger: '2.0'
basePath: /
schemes:
  - http
paths:
  '/toggle':
    post:
      summary: Toggle the switch
      description: If switch is off, toggle to on, and vice versa.
      responses:
        200:
          description: Success
Command line used for generation
swagger-codegen generate -i example.yaml -l python -o $OUTPUT_DIR
Steps to reproduce

Generate a python client using an API spec that includes a POST path with no body parameters. Use the client to make a request, and observe that the request has a "Content-Type" header.

Related issues/PRs

#5613
#6647

Suggest a fix/enhancement

Only add a Content-Type header is body parameters are specified: #6648

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 by inspecting the generated Python client's request construction for operations without body parameters, using the POST /toggle example from the issue. Compare the behavior with related issue #6647 and proposed fix #6648. Done means a bodyless request no longer includes a Content-Type header, while requests with body parameters still do.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.