OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Python] generated api_client Can not handle Put Request if Server return 204 or 201

Open
#6,842 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • [ ✅] Have you provided a full/minimal spec to reproduce the issue?
  • [ ✅] Have you validated the input using an OpenAPI validator (example)?
  • [ ✅] What's the version of OpenAPI Generator used?
  • [ ✅] Have you search for related issues/PRs?
  • [ ✅] What's the actual output vs expected output?
  • [✅ ] [Optional] Bounty to sponsor the fix (example)
Description

in generated python client if server handle Put Request as [create or update] and in case of update server return 204
and python client expect the return will contain object then it try to deserialize empty string to object an fail

openapi-generator version

docker version cli-latest.

OpenAPI declaration file content or url
Command line used for generation
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i file_test.json \
    -g python \
    -o /local/out/python
Steps to reproduce
import openapi_client
Related issues/PRs
Suggest a fix

in generated python client in api_client.py in this condition

if response_type:
    return_data = self.deserialize(response_data, response_type)

to by like

if response_type and (content_type is not None or response_data.data != ''):
    return_data = self.deserialize(response_data, response_type)

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

Begin in the generated Python client's api_client.py at the response_type deserialization condition; reproduce with the provided Docker generation command and a PUT response with status 204 or 201. Done means an empty response is not deserialized as the declared object while non-empty responses retain current behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.