Open danielbprice opened 1 year ago
I found by experiment that changing line 183 of connexion/decorators/uri_parsing.py
elif 'contentType' in encoding and utils.all_json([x.strip() for x in encoding.get('contentType').split(',')]):
form_data[k] = json.loads(form_data[k])
Seemed to do the trick, but I don't know if other instances are lurking in the code.
My reading of the code on main
says that this problem is still there, although I have not tested against it.
Description
We are developing an application which accepts multipart form data for a file upload of an image. We have:
(I have omitted some fields from this spec for brevity; they appear in the traceback below but are not relevant here)
Expected behaviour
We constructed a test case in which we passed non-file data to
image
, to make sure the endpoint would cleanly handle this case, essentially:Actual behaviour
We see a traceback. It seems that the logic which is checking to see encoding.image.contentType is JSON-y is not handling the case in which there is a comma-separated list of MIME types. This is permitted by the OpenAPI 3.0.3 spec as per "Encoding Object" (The Content-Type for encoding a specific property. Default value depends on the property type: for object - application/json; for array – the default is defined based on the inner type; for all other cases the default is application/octet-stream. The value can be a specific media type (e.g. application/json), a wildcard media type (e.g. image/*), or a comma-separated list of the two types.)
Indeed, changing the
contentType: image/png, image/jpeg
line tocontentType: image/*
makes the problem go away.Steps to reproduce
Additional info:
Output of the commands:
python --version
: Python 3.10.12pip show connexion | grep "^Version\:"
: Version: 2.14.2