Repository: encode/django-rest-framework

Issue:
integer types that are greater than 32bit should use format int64
## Checklist

- [X] I have verified that that issue exists against the `master` branch of Django REST framework.
- [X] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [X] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.)
- [X] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](https://www.django-rest-framework.org/community/third-party-packages/#about-third-party-packages) where possible.)
- [X] I have reduced the issue to the simplest possible case.
- [X] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

## Steps to reproduce
Create a project that uses a django 2.1.x PositiveIntegerField in the api.  Use drf to generate an openapi spec

## Expected behavior
the field should be represented as a `type` field of `integer` and there should be a `format` field of `int64`

## Actual behavior
the field has `type` field of `integer`, but there is no `format` field of `int64`


Discussion:

Resolving patch:
diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py
--- a/rest_framework/schemas/openapi.py
+++ b/rest_framework/schemas/openapi.py
@@ -265,9 +265,13 @@ def _map_field(self, field):
                 '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
@@ -337,6 +341,9 @@ def _map_field(self, field):
                 '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
 
         # Simplest cases, default to 'string' type:


Test patch:
diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py
--- a/tests/schemas/test_openapi.py
+++ b/tests/schemas/test_openapi.py
@@ -48,6 +48,10 @@ def test_list_field_mapping(self):
             (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):