Repository: encode/django-rest-framework

Issue:
OpenApi AutoSchema inspection produces invalid type `null` on ArrayField(base_field=ChoicesField())
## 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.
- [ ] 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 array field with base_field provided choices:

```python
class A(Model):
	field = ArrayField(base_field=CharField(max_length=256, choices=(1,2,3)))
```

## Expected behavior

```js
properties: {field: {
	type: array
	items: {
		enum: [1, 2, 3]
		type: "string"
	}
}}
```

or

```js
properties: {field: {
	type: array
	items: {
		enum: [1, 2, 3]
	}
}}
```


## Actual behavior

```js
properties: {
field: {
	type: array
	items: {
		type: null
	}
}}
```

## Note

Looks like choice field processing produces `{enum}`
https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/openapi.py#L256

But list field expects `type` (`self._map_field(field.child).get('type')`)
https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/openapi.py#L269

Add failing test case for schema generation
**Notes**:
As per OpenAPI specs, type is required. While generating schema, type is not provided for choice field. This leads to wrong schema in swagger and javascript error in redoc.

Someone has already reported this issue. See #7023


Discussion:
I have same issue. I would like to fix this issue.


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
@@ -268,13 +268,7 @@ def _map_field(self, field):
                 'items': {},
             }
             if not isinstance(field.child, _UnvalidatedField):
-                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
+                mapping['items'] = self._map_field(field.child)
             return mapping
 
         # DateField and DateTimeField type is string


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
@@ -51,7 +51,9 @@ def test_list_field_mapping(self):
             (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'}),
+             {'items': {'type': 'integer', 'maximum': 4294967295, 'format': 'int64'}, 'type': 'array'}),
+            (serializers.ListField(child=serializers.ChoiceField(choices=[('a', 'Choice A'), ('b', 'Choice B')])),
+             {'items': {'enum': ['a', 'b']}, 'type': 'array'}),
             (serializers.IntegerField(min_value=2147483648),
              {'type': 'integer', 'minimum': 2147483648, 'format': 'int64'}),
         ]