-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
DRF doesn't change the media type of request body to multipart/form-data automatically #6863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah seems valid to me. Of course it’s less obvious what we should do if we have both FileField and composite field types (that multipart can’t support.) |
Could you please give an example of request body with file and composite field? |
Eg. Anything with both FileField and DictField |
Or FileField and a nested serializer |
@knivets you fancy taking a pop at this? As Tom says, we should be able to do the simple cases at least. (There may come a complexity level where we say “use a subclass to specify this particular case” rather than try and solve everything, but we’re not there yet...) |
Yes! I’ll work on this over the weekend. |
@knivets Do you have an idea what is the expected schema using OpenAPI Components ? In the example you posted in "Expected behavior", the I wasn't able to find any example about this on the web. |
Checklist
master
branch of Django REST framework.Steps to reproduce
Expected behavior
Actual behavior
There are two things going on here:
multipart/form-data
media type generationFileField
generates incomplete OpenAPI schema: it doesn't includeformat: binary
. Finally, it should only generateformat: binary
for requests, since you can't have a binary string field withinapplication/json
media type. We could probably add aformat: uri
in caseuse_url=True
.https://swagger.io/docs/specification/describing-request-body/multipart-requests/
On unrelated note I noticed that DRF doesn't put
type: object
underschema
even though this spec passes validation hereThe text was updated successfully, but these errors were encountered: