-
Notifications
You must be signed in to change notification settings - Fork 260
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
fix: BinaryField's schema type should be string #505 #506
Changes from 1 commit
54af383
6a41f43
0e4e76f
a7bfcb3
cb40727
c4daa0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -435,6 +435,8 @@ def _map_model_field(self, model_field, direction): | |||||
elif hasattr(models, 'JSONField') and isinstance(model_field, models.JSONField): | ||||||
# fix for DRF==3.11 with django>=3.1 as it is not yet represented in the field_mapping | ||||||
return build_basic_type(OpenApiTypes.OBJECT) | ||||||
elif hasattr(models, 'BinaryField') and isinstance(model_field, models.BinaryField): | ||||||
return build_basic_type(OpenApiTypes.STR) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong to me. drf-spectacular/drf_spectacular/types.py Line 68 in 508f4e5
If this were Base64 encoded we should be using drf-spectacular/drf_spectacular/types.py Line 67 in 508f4e5
See the data types section for OpenAPI v3.0.3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right! I fixed for OpenApiTypes.BYTE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've misunderstood me - this should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused. JSON format should be base64 type. I fixed for OpenApiTypes.BINARY. |
||||||
elif hasattr(models, model_field.get_internal_type()): | ||||||
# be graceful when the model field is not explicitly mapped to a serializer | ||||||
internal_type = getattr(models, model_field.get_internal_type()) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BinaryField
has existed since Django 1.6, so we don't need to check whether it exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is safe. Not happened nothing. We do not want get error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unnecessary. Django 1.5 has been end-of-life for years - long before this package existed.
The equivalent check for
JSONField
is required as that was added more recently in Django 3.1 and Django 2.2 is still supported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well. I will fix.