Skip to content

Python client only accepting Json in body parameters of POST requests #3723

@bkryza

Description

@bkryza
Description

Python client seems to only accept JSON Content in the body of POST requests, other formats must be sent in formData.

Swagger-codegen version

master

Swagger declaration file content or url

See the following Gist: echo-xml.yaml

Command line used for generation
cd swagger-codegen

mvn package

vim echo-xml.yaml # Paste the above example

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l swagger -i ./echo-xml.yaml -o ./output/echo-xml

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l swagger -i ./samples/yaml/echo-xml.yaml -o ./output/echo-xml
Steps to reproduce

Generate the Python client using the above steps.

Then create an echo-xml-test.py in the swagger-codegen folder and run the script. Server is not necessary, as the client fails before making any HTTP requests:

> swagger-codegen git:(master):  python echo-xml-test.py
Traceback (most recent call last):
  File "echo-xml-test.py", line 43, in <module>
    echo_api.echo(message=echo_message, callback=None)
  File "./output/python/swagger_client/apis/default_api.py", line 78, in echo
    (data) = self.echo_with_http_info(message, **kwargs)
  File "./output/python/swagger_client/apis/default_api.py", line 160, in echo_with_http_info
    collection_formats=collection_formats)
  File "./output/python/swagger_client/api_client.py", line 313, in call_api
    _return_http_data_only, collection_formats)
  File "./output/python/swagger_client/api_client.py", line 147, in __call_api
    post_params=post_params, body=body)
  File "./output/python/swagger_client/api_client.py", line 350, in request
    body=body)
  File "./output/python/swagger_client/rest.py", line 210, in POST
    body=body)
  File "./output/python/swagger_client/rest.py", line 167, in request
    r = RESTResponse(r)
UnboundLocalError: local variable 'r' referenced before assignment
Related issues
Suggest a Fix

The problem is in the rest.mustache file, which for body parameters only checks for json mimeType. For body parameters it should also allow other "text" formats such as xml, yaml, plain, etc...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions