Skip to content
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 compatibility with django-rest-framework 3.14.0 having depreciated NullBooleanField #814

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/drf_yasg/inspectors/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import operator
import typing
import uuid
import pkg_resources
from packaging import version
from collections import OrderedDict
from decimal import Decimal
from inspect import signature as inspect_signature
Expand All @@ -20,6 +22,9 @@
)
from .base import FieldInspector, NotHandled, SerializerInspector, call_view_method


drf_version = pkg_resources.get_distribution("djangorestframework").version

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -376,7 +381,6 @@ def decimal_field_type(field):
(models.AutoField, (openapi.TYPE_INTEGER, None)),
(models.BinaryField, (openapi.TYPE_STRING, openapi.FORMAT_BINARY)),
(models.BooleanField, (openapi.TYPE_BOOLEAN, None)),
(models.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
(models.DateTimeField, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)),
(models.DateField, (openapi.TYPE_STRING, openapi.FORMAT_DATE)),
(models.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)),
Expand All @@ -390,7 +394,7 @@ def decimal_field_type(field):
(models.TimeField, (openapi.TYPE_STRING, None)),
(models.UUIDField, (openapi.TYPE_STRING, openapi.FORMAT_UUID)),
(models.CharField, (openapi.TYPE_STRING, None)),
]
]

ip_format = {'ipv4': openapi.FORMAT_IPV4, 'ipv6': openapi.FORMAT_IPV6}

Expand All @@ -403,7 +407,6 @@ def decimal_field_type(field):
(serializers.RegexField, (openapi.TYPE_STRING, None)),
(serializers.CharField, (openapi.TYPE_STRING, None)),
(serializers.BooleanField, (openapi.TYPE_BOOLEAN, None)),
(serializers.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
(serializers.IntegerField, (openapi.TYPE_INTEGER, None)),
(serializers.FloatField, (openapi.TYPE_NUMBER, None)),
(serializers.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)),
Expand All @@ -413,6 +416,15 @@ def decimal_field_type(field):
(serializers.ModelField, (openapi.TYPE_STRING, None)),
]

if version.parse(drf_version) < version.parse("3.14.0"):
model_field_to_basic_type.append(
(models.NullBooleanField, (openapi.TYPE_BOOLEAN, None))
)

serializer_field_to_basic_type.append(
(serializers.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
)

basic_type_info = serializer_field_to_basic_type + model_field_to_basic_type


Expand Down Expand Up @@ -840,3 +852,4 @@ def field_to_swagger_object(self, field, swagger_object_type, use_references, **
return ref

return NotHandled