swagger-api / swagger-api/swagger-codegen
[PYTHON] Bug: client applies Content-Type header when no request body is present
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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