swagger-api / swagger-api/swagger-codegen
Python client should support overriding special HTTP headers
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The python client should allow overriding the Accept and Content-Type headers by the caller of API functions.
Right now, the Accept header is automatically set when 'produces' is defined in the service description and Content-Type is set when 'consumes' is defined. On the other hand, an end user might want to explicitly specify the return format of a certain request. This is the case with file downloads in a given format.
Swagger-codegen version
> java.exe -jar .\swagger-codegen-cli.jar version
2.3.1
Swagger declaration file content or url
Any file that has produces and/or consumes definitions.
Suggest a fix/enhancement
The easiest solution is to set the default Accept and Content-Type before looping through the actual parameters. This way, if the user specifies the accept header, it would simply overwrite the default. Same applies to Content-Type. This would involve moving a few lines starting from https://github.com/swagger-api/swagger-codegen/blob/03ed4334f81dea6329065a214a2429ded92190ff/modules/swagger-codegen/src/main/resources/python/api.mustache#L183 before https://github.com/swagger-api/swagger-codegen/blob/03ed4334f81dea6329065a214a2429ded92190ff/modules/swagger-codegen/src/main/resources/python/api.mustache#L163
I can imagine more sophisticated approaches, however. For example, passing on the entire kwargs or all_params to self.api_client.call_api would allow overriding behavior at a single place (by overriding function in ApiClient.
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 in modules/swagger-codegen/src/main/resources/python/api.mustache, around the linked header setup and parameter loop. Check how Accept and Content-Type defaults are assigned and how caller-supplied headers are processed. Done means generated Python API functions let callers override those defaults, including for file downloads; validate against a generated client from a declaration containing produces or consumes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100