In openapi 3 mode if we create a method such as post or put that accepts json and returns json along with type: object in schema then the method fails with the below error.
Traceback (most recent call last):
File "/c/w/connexion/venv/src/flask/flask/app.py", line 2310, in wsgi_app
response = self.full_dispatch_request()
File "/c/w/connexion/venv/src/flask/flask/app.py", line 1833, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/c/w/connexion/venv/src/flask/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/c/w/connexion/venv/src/flask/flask/_compat.py", line 40, in reraise
raise value
File "/c/w/connexion/venv/src/flask/flask/app.py", line 1831, in full_dispatch_request
rv = self.dispatch_request()
File "/c/w/connexion/venv/src/flask/flask/app.py", line 1817, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/decorators/decorator.py", line 48, in wrapper
response = function(request)
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/decorators/uri_parsing.py", line 143, in wrapper
response = function(request)
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/decorators/validation.py", line 172, in wrapper
response = function(request)
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/decorators/parameter.py", line 108, in wrapper
request.files, arguments, has_kwargs, sanitize)
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/operations/abstract.py", line 275, in get_arguments
has_kwargs, sanitize))
File "/c/w/connexion/venv/lib/python3.7/site-packages/connexion-2018.0.dev1-py3.7.egg/connexion/operations/openapi.py", line 268, in _get_body_argument
body_arg.update(body or {})
TypeError: cannot convert dictionary update sequence element #0 to a sequence
127.0.0.1 - - [04/Mar/2019 21:10:14] "POST /v1.0/greeting HTTP/1.1" 500 -
connexion should work as expected returning json as the argument .
Error shown in the description
To reproduce the error use the helloobj example shown in this branch.
https://github.com/zalando/connexion/compare/master...ngcloud:fix/dict-error-post
cd examples/openapi3/helloobj
python hello.py
# Visit the swagger ui and make a post request
# http://localhost:9090/v1.0/ui/#/default/hello.post_greeting
# curl -X POST "http://localhost:9090/v1.0/greeting" -H "accept: application/json" -H "Content-Type: applicaton/json" -d "{\"name\":\"fluffy\"}"
Output of the commands:
python --versionPython 3.7.2+
pip show connexion | grep "^Version\:"Version: 2018.0.dev1
I have attempted a fix here - https://github.com/zalando/connexion/commit/518d1dd3d711782aa56eb406b7fb346443d94271
Hey @prabhu - you have a typo applicaton/json in your spec and your curl request.
You need to use applicat i on/json (note the missing 'i').
Wow, I am feeling ashamed a bit here :) But thank you very much for this!
No worries!
On Thu, Mar 7, 2019 at 5:45 PM Prabhu Subramanian notifications@github.com
wrote:
Wow, I am feeling ashamed a bit here :) But thank you very much for this!
—
You are receiving this because you modified the open/close state.Reply to this email directly, view it on GitHub
https://github.com/zalando/connexion/issues/892#issuecomment-470413521,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlPSUBEc8Ub3gMxGaEXJ8MngHkoX75mks5vULx0gaJpZM4bdO76
.
I have attempted a fix here - 518d1dd
I got same error. My headers were named correctly. Application is somewhat complex (OpenAPI spec is about 7000lines) and the server stub was generated with OpenAPI generator
This error appeared in every PUT and POST request so far, and changes in OpenAPI spec did not change anything in my knowledge. Spec is here for anyone interested: spec
However, adding your potential fix fixed my problem!
@Nicceboy Glad the patch helped. I think you need this patch because of the content-type used being
application/vnd.mason+json . If you change it to application/json it should work without the patch
I tried out with application/json as well, but no luck. application/vnd.mason+json is on Accept and Response Content-Type headers only, not in any request Content-Type header.
Looks like there was typo in my OpenAPI spec after all. requestBody in component section was defined to be '*/*'. Change for application/json made it work like a charm, without additional fixes.
I ran into a lot of confusion here, as I was trying to allow for multiple content media types in the request body (which is supported in openapi3), like in the following example adapted from here:
[...]
requestBody:
required: true
content:
application/json:
schema:
x-body-name: user
$ref: "#/components/schemas/User"
application/:x-www-form-urlencoded
schema:
x-body-name: user
$ref: "#/components/schemas/User"
[...]
When removing the second media type everything works as it should, but I have yet to understand how to handle multiple media types. (I am sending requests through the swagger-ui, as well as through flask's .post on an app.test_client())
P.S. This is partly an invitation to reply if you know how to make this work, partly meant as a google-able note for people making the same mistake.
Most helpful comment
I ran into a lot of confusion here, as I was trying to allow for multiple content media types in the request body (which is supported in openapi3), like in the following example adapted from here:
When removing the second media type everything works as it should, but I have yet to understand how to handle multiple media types. (I am sending requests through the swagger-ui, as well as through flask's
.poston anapp.test_client())P.S. This is partly an invitation to reply if you know how to make this work, partly meant as a google-able note for people making the same mistake.