diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index a67974ed6..0d45e27cf 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -268,9 +268,13 @@ class AutoSchema(ViewInspector): 'items': {}, } if not isinstance(field.child, _UnvalidatedField): - mapping['items'] = { - "type": self._map_field(field.child).get('type') + map_field = self._map_field(field.child) + items = { + "type": map_field.get('type') } + if 'format' in map_field: + items['format'] = map_field.get('format') + mapping['items'] = items return mapping # DateField and DateTimeField type is string @@ -340,6 +344,9 @@ class AutoSchema(ViewInspector): 'type': 'integer' } self._map_min_max(field, content) + # 2147483647 is max for int32_size, so we use int64 for format + if int(content.get('maximum', 0)) > 2147483647 or int(content.get('minimum', 0)) > 2147483647: + content['format'] = 'int64' return content if isinstance(field, serializers.FileField): diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index bbdae0fed..fc22c32ab 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -50,6 +50,10 @@ class TestFieldMapping(TestCase): (serializers.ListField(child=serializers.BooleanField()), {'items': {'type': 'boolean'}, 'type': 'array'}), (serializers.ListField(child=serializers.FloatField()), {'items': {'type': 'number'}, 'type': 'array'}), (serializers.ListField(child=serializers.CharField()), {'items': {'type': 'string'}, 'type': 'array'}), + (serializers.ListField(child=serializers.IntegerField(max_value=4294967295)), + {'items': {'type': 'integer', 'format': 'int64'}, 'type': 'array'}), + (serializers.IntegerField(min_value=2147483648), + {'type': 'integer', 'minimum': 2147483648, 'format': 'int64'}), ] for field, mapping in cases: with self.subTest(field=field):