swagger-api / swagger-api/swagger-codegen

[python] does not honour different response types for different return codes

Open
#5,186 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Enhancement: Feature help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When an API spec defines different response types for several status codes, the code generator does not seem to take this into account and tries to parse the response into a particular object of the model (I suspect that defined for status 200 or maybe the first one found) without checking the code first.

I have an API that returns some json on code 200 and a file in 201, so when I get a file, the generated client tries to parse it as the object and I end up not getting the file contents at all.

I have worked around this by using the _with_http_info calls and passing the _preload_content=False argument to it, but it is rather raw and it introduces a difference to how I check the responses.

Suggest a Fix

The response_type parameter to ApiClient.call_api could be a dictionary of status-code -> response_type. Then depending on the received status code, use one type or the other to process the response.

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 Python ApiClient.call_api entry point and trace how response_type is selected and applied after an HTTP response. Verify behavior for multiple status codes, including JSON for 200 and a file for 201; done means each response is processed according to its returned status code without requiring _preload_content=False.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.