swagger-api / swagger-api/swagger-codegen-generators

[python] python client returns a bad binary representation of string for text/plain responses

Open
#1,347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

With this response type

    responses:
      200:
        description: success
        content:
           text/plain:
             schema:
               type: string
               example: ok

The you get the following response from the generated client:

"b'ok'"

This is due to the fact the retuned body is in bytes and then the deserialisation tries to make a string of it and in newer python this generates a repr of the bytes which corresponds to this string.

The proper way would be to decode the binary body according to charset returned or ascii for all content type "text/" before any fancy handling of the swagger specific types.

Then maybe also the str conversion in serialisation can be removed for string type.

I will send a pull request solving this in a moment.

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 generated Python client's response deserialization and serialization paths for text/plain responses. Reproduce the example with a string response, then verify that the client returns the decoded string rather than a bytes representation and that existing generated-client tests still pass.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.