Closed hossainirad closed 2 years ago
ImageField
will be a string on response and a binary blob on request.'COMPONENT_SPLIT_REQUEST': True
,because this duality cannot be modeled in one OpenAPI component.parser_classes = [parsers.MultiPartParser]
as the json parser cannot handle binary blobs. spectacular will pick this up automatically.apart from that you code example should then work as expected. the manual schema from #476 should not be needed then.
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.
@tfranzel COMPONENT_SPLIT_REQUEST: True
is the key here, but unfortunately, changing this setting mid-project results in change of entire schema and hence generated api clients.
Is it possible to override this only for a single viewset somehow?
sry, this is a global setting. usage of COMPONENT_SPLIT_REQUEST: True
is highly recommended in the docs when someone wants generate clients.
I recommend switching because it will save you time down the line. it produces vastly superior clients.
@tfranzel Thank you for the reply. I was able to reach FAQ section where you mentioned it https://github.com/tfranzel/drf-spectacular/blob/2501bfd1f74fedacdec4051adc76df22bc847976/docs/faq.rst#filefield-imagefield-is-not-handled-properly-in-the-schema
Unfortunately, when we started the project, COMPONENT_SPLIT_REQUEST: False
was the default (may-be even today) and we didn't cared about it, until yesterday when we needed a file upload endpoint.
We are checking at our end, if somehow we can incorporate w/o disrupting mobile/web client apps in a major way. Alternatively, we might end up with vanilla Django upload endpoint w/ out-of-bound authentication/permission checks.
sry to hear that. well there is a whole section in the docs about this topic: https://drf-spectacular.readthedocs.io/en/latest/client_generation.html
I migrated a project once before and the required changes are usually not too bad.
InputSerializer have some ImageField that come from a model. how can I have an input file for them in docs record?
I have seen https://github.com/tfranzel/drf-spectacular/issues/476 but how can a use them together? thanks for your time!