Skip to content

[Bug][Python]Support body as bytes when Content-Type is unknown#2626

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
sarod:issue#2623
Apr 26, 2019
Merged

[Bug][Python]Support body as bytes when Content-Type is unknown#2626
wing328 merged 3 commits intoOpenAPITools:masterfrom
sarod:issue#2623

Conversation

@sarod
Copy link
Contributor

@sarod sarod commented Apr 8, 2019

fix #2623

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Accept body as bytes to support binary content types like application/octet-stream

@sarod
Copy link
Contributor Author

sarod commented Apr 8, 2019

@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01)
Please review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should probably be updated but I'm not sure I understand the last part 'when body argument is provided in serialized form' so I chose to let it untouched for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarod My "guess" is that the body can simply a string, e.g. "OK" or a boolean value (e.g. true), or just an integer, e.g. 2019.

Usually, the HTTP request body is JSON payload and I did see a few cases in which a string/number is used.

@wing328
Copy link
Member

wing328 commented Apr 18, 2019

Travis CI reports errors partially shown below:

======================================================================
ERROR: Failure: SyntaxError (from __future__ imports must occur at the beginning of the file (rest.py, line 13))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/lib/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/tests/test_store_api.py", line 16, in <module>
    import petstore_api
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/petstore_api/__init__.py", line 20, in <module>
    from petstore_api.api.another_fake_api import AnotherFakeApi
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/petstore_api/api/__init__.py", line 6, in <module>
    from petstore_api.api.another_fake_api import AnotherFakeApi
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/petstore_api/api/another_fake_api.py", line 20, in <module>
    from petstore_api.api_client import ApiClient
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/petstore_api/api_client.py", line 27, in <module>
    from petstore_api import rest
  File "/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/petstore_api/rest.py", line 13
    from __future__ import absolute_import
                                         ^
SyntaxError: from __future__ imports must occur at the beginning of the file

Name                                                                      Stmts   Miss  Cover
---------------------------------------------------------------------------------------------
petstore_api/configuration.py                                                97     68    30%
petstore_api/models/__init__.py                                              46      0   100%
petstore_api/models/additional_properties_any_type.py                        38     23    39%
petstore_api/models/additional_properties_array.py                           38     23    39%
petstore_api/models/additional_properties_boolean.py                         38     23    39%
petstore_api/models/additional_properties_class.py                          108     73    32%
petstore_api/models/additional_properties_integer.py                         38     23    39%
petstore_api/models/additional_properties_number.py                          38     23    39%
petstore_api/models/additional_properties_object.py                          38     23    39%
petstore_api/models/additional_properties_string.py                          38     23    39%
petstore_api/models/animal.py                                                51     32    37%
petstore_api/models/api_response.py                                          52     33    37%
petstore_api/models/array_of_array_of_number_only.py                         38     23    39%
petstore_api/models/array_of_number_only.py                                  38     23    39%
petstore_api/models/capitalization.py                                        73     48    34%
petstore_api/models/cat.py                                                   38     23    39%
petstore_api/models/category.py                                              46     29    37%
petstore_api/models/class_model.py                                           38     23    39%
petstore_api/models/client.py                                                38     23    39%
petstore_api/models/dog.py                                                   38     23    39%
petstore_api/models/enum_arrays.py                                           51     34    33%
petstore_api/models/enum_class.py                                            34     18    47%
petstore_api/models/file.py                                                  38     23    39%
petstore_api/models/has_only_read_only.py                                    45     28    38%
petstore_api/models/list.py                                                  38     23    39%
petstore_api/models/mixed_properties_and_additional_properties_class.py      52     33    37%
petstore_api/models/model200_response.py                                     45     28    38%
petstore_api/models/model_return.py                                          38     23    39%
petstore_api/models/name.py                                                  60     39    35%
petstore_api/models/number_only.py                                           38     23    39%
petstore_api/models/order.py                                                 76     51    33%
petstore_api/models/outer_composite.py                                       52     33    37%
petstore_api/models/outer_enum.py                                            34     18    47%
petstore_api/models/pet.py                                                   78     53    32%
petstore_api/models/read_only_first.py                                       45     28    38%
petstore_api/models/special_model_name.py                                    38     23    39%
petstore_api/models/tag.py                                                   45     28    38%
petstore_api/models/type_holder_default.py                                   71     48    32%
petstore_api/models/type_holder_example.py                                   71     48    32%
petstore_api/models/user.py                                                  87     58    33%
petstore_api/models/xml_item.py                                             234    163    30%
---------------------------------------------------------------------------------------------
TOTAL                                                                      2237   1405    37%
----------------------------------------------------------------------
Ran 60 tests in 0.369s

FAILED (errors=60)
Using 404908369 as seed
ERROR: InvocationError for command /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/python/.tox/py3/bin/nosetests (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py27: commands failed
ERROR:   py3: commands failed
make: *** [test-all] Error 1
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (nose-test) on project PythonPetstoreClientTests: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]

Ref: https://travis-ci.org/OpenAPITools/openapi-generator/builds/517324159

@wing328 wing328 added this to the 4.0.0 milestone Apr 18, 2019
@wing328
Copy link
Member

wing328 commented Apr 18, 2019

Support body as bytes when Content-Type is unknown

What about updating the spec to specify the consumes (OASv2) of the operation instead?

@sarod
Copy link
Contributor Author

sarod commented Apr 19, 2019

The spec in my issue uses openapi: 3.0.0 and specifies requestBody.content as a replacement of consumes.

@sarod sarod mentioned this pull request Apr 19, 2019
@sarod
Copy link
Contributor Author

sarod commented Apr 23, 2019

@wing328 All tests are passing now.

@wing328
Copy link
Member

wing328 commented Apr 24, 2019

@sarod 👍

If no one has further feedback on this PR, I'll merge it on coming Friday.

@wing328 wing328 merged commit 567eb6c into OpenAPITools:master Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Python] Can't send binary payload using Python3 and Python client

2 participants