From f5b0cb878d27952f350b6aa871bd6b73e065bc09 Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Fri, 21 Feb 2020 17:26:56 -0800 Subject: [PATCH] Fix duration field inspector - Durations should be represented as an `openapi.TYPE_STRING` so swagger and other tools do not prevent valid input ("00:10:00" is valid, but not a number) See: https://www.django-rest-framework.org/api-guide/fields/#durationfield and https://docs.djangoproject.com/en/3.0/ref/utils/#django.utils.dateparse.parse_duration --- src/drf_yasg/inspectors/field.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drf_yasg/inspectors/field.py b/src/drf_yasg/inspectors/field.py index 09386363..9a16a3ca 100644 --- a/src/drf_yasg/inspectors/field.py +++ b/src/drf_yasg/inspectors/field.py @@ -380,7 +380,7 @@ def decimal_field_type(field): (models.DateTimeField, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)), (models.DateField, (openapi.TYPE_STRING, openapi.FORMAT_DATE)), (models.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)), - (models.DurationField, (openapi.TYPE_INTEGER, None)), + (models.DurationField, (openapi.TYPE_STRING, None)), (models.FloatField, (openapi.TYPE_NUMBER, None)), (models.IntegerField, (openapi.TYPE_INTEGER, None)), (models.IPAddressField, (openapi.TYPE_STRING, openapi.FORMAT_IPV4)), @@ -407,7 +407,7 @@ def decimal_field_type(field): (serializers.IntegerField, (openapi.TYPE_INTEGER, None)), (serializers.FloatField, (openapi.TYPE_NUMBER, None)), (serializers.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)), - (serializers.DurationField, (openapi.TYPE_NUMBER, None)), # ? + (serializers.DurationField, (openapi.TYPE_STRING, None)), (serializers.DateField, (openapi.TYPE_STRING, openapi.FORMAT_DATE)), (serializers.DateTimeField, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)), (serializers.ModelField, (openapi.TYPE_STRING, None)),