django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

OpenAPI schema for FileField/ImageField is always string/binary

Open denisorehovsky opened this issue 2 years ago • 0 comments

Checklist

  • [x] Raised initially as discussion https://github.com/encode/django-rest-framework/issues/6863
  • [x] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • [x] I have reduced the issue to the simplest possible case.

Request and response schemas have the same format for FileField and ImageField:

"some_field": {
    "type": "string",
    "format": "binary"
}

However, it's not correct. If you look at implementation of FileField, you will see that to_representation always returns string: image

Response format should be url or no format at all if UPLOADED_FILES_USE_URL is false.

This was initially mentioned in https://github.com/encode/django-rest-framework/issues/6863

denisorehovsky avatar Aug 28 '22 06:08 denisorehovsky