From 54af383b5ae00b6f029896263462890687b1ac0b Mon Sep 17 00:00:00 2001 From: Johannes Tamm Date: Tue, 7 Sep 2021 14:16:39 +0300 Subject: [PATCH 1/5] fix: BinaryField's schema type should be string #505 --- drf_spectacular/openapi.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index 505250c6..95c9abc3 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -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) 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()) From 6a41f433365d8260e28f98418f1c8f1d2f8dd0b5 Mon Sep 17 00:00:00 2001 From: Johannes Tamm Date: Wed, 8 Sep 2021 08:53:22 +0300 Subject: [PATCH 2/5] fix: BinaryField's schema type should be byte #505 --- drf_spectacular/openapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index 95c9abc3..a7c32044 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -436,7 +436,7 @@ def _map_model_field(self, model_field, direction): # 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) + return build_basic_type(OpenApiTypes.BYTE) 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()) From 0e4e76f8679c2bb68ea1d31cc24dffdee21be998 Mon Sep 17 00:00:00 2001 From: Johannes Tamm Date: Wed, 8 Sep 2021 09:23:22 +0300 Subject: [PATCH 3/5] fix: BinaryField's schema type should be binary #505 --- drf_spectacular/openapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index a7c32044..51c93ded 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -435,8 +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.BYTE) + elif isinstance(model_field, models.BinaryField): + return build_basic_type(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()) From a7bfcb3dff5aab63e8df886bc784329d0db22843 Mon Sep 17 00:00:00 2001 From: Johannes Tamm Date: Wed, 8 Sep 2021 14:26:50 +0300 Subject: [PATCH 4/5] revert: OpenApiTypes.BYTE #505 --- drf_spectacular/openapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index 51c93ded..ad32c94e 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -436,7 +436,7 @@ def _map_model_field(self, model_field, direction): # 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 isinstance(model_field, models.BinaryField): - return build_basic_type(OpenApiTypes.BINARY) + return build_basic_type(OpenApiTypes.BYTE) 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()) From cb40727687559952b85372ababf28d6d2fd28ad3 Mon Sep 17 00:00:00 2001 From: Johannes Tamm Date: Tue, 7 Sep 2021 14:16:39 +0300 Subject: [PATCH 5/5] fix: BinaryField's schema type should be byte #505 --- drf_spectacular/openapi.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index 505250c6..ad32c94e 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -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 isinstance(model_field, models.BinaryField): + return build_basic_type(OpenApiTypes.BYTE) 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())