-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add extension blueprint for drf-extra-fields Base64FileField #579
Comments
Base64 format for OpenAPI 3.0: Base64 format for OpenAPI 3.1: |
What Request: |
Hey, you are referencing the wrong spec (3.0.1).. this changed for 3.0.3 https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types
The output is likely because that field is derived from DRF's
Nope, you would need to create a OpenApiSerializerFieldExtension to override the behavior for that modified subclass. This is the preferred way to "annotate" functionality that originates from inaccessible library code. The whole point of extensions is so that you don't need to do this: @extend_schema_field(OpenApiTypes.STR)
class SpectacularBase64ImageField(Base64ImageField): |
@tfranzel Reading the Extensions guide, how does one register an Extension? Or do they get automatically discovered? |
It works similar to celery tasks. They get registered once they are seen by the interpreter. It's in the blueprint docs but should also be mentioned there again probably |
|
@tfranzel Would you be able to advise which Request: I will also need to control the Required field as well. I plan to submit this as a blueprint PR for others once completed. |
PR for this in #583 |
The
drf-extra-fields
Base64FileField
/Base64ImageField
provide a to define a file field in which files are sent as requests as base64 string instead of binary blobs, and can be pulled down as responses as base64 string or URL.Out of the box
drf-spectacular
seems to treat them as normal file fields (e.g. that binary should be pushed up). I'd like to contribute an extension blueprint for how to properly model these indrf-spectacular
.Here is a PR for how this was done in
drf-yasg
: axnsan12/drf-yasg#445This simply sets the type as a string and also sets
read_only
toFalse
(I think theread_only
part isdrf-yasg
specific and has to do with OpenAPI 2 not being able to split request and response).The best I've been able to come up with so far is:
But in theory we could do better. Ideally we'd want OpenAPI 3 something like:
Request:
string($base64)
Response:
string($uri)
And then for fields defined like:
To annotate OpenAPI 3 like:
Request:
string($base64)
Response:
string($base64)
Is there a way to accomplish dual-sided schema generation with
@extend_schema_field
?The text was updated successfully, but these errors were encountered: