Repository: encode/django-rest-framework

Issue:
Schema generation with an HStoreField gives an incorrect type
## 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

On any serializer, add an HStoreField.

``` python
class HStoredSerializer(serializers.Serializer):
    myfield = serializers.HStoreField()

class HStoredAPIView(CreateAPIView):
    serializer_class = HStoredSerializer
    ...
```

## Expected behavior

Output of `./manage.py generateschema`:

``` yaml
paths:
  /api/hstored:
    post:
      operationId: CreateHStored
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              required:
              - myfield
              properties:
                myfield:
                  type: object
```

## Actual behavior

Output of `./manage.py generateschema`:

``` yaml
paths:
  /api/hstored:
    post:
      operationId: CreateHStored
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              required:
              - myfield
              properties:
                myfield:
                  type: string
```

It seems that we should only need to add a line to the `FIELD_CLASS_SCHEMA_TYPE` dict [found here](https://github.com/encode/django-rest-framework/blob/89ac0a1c7ef6153312890376ac142674b28b04f1/rest_framework/schemas/openapi.py#L343); if that's all we need, I can easily open a PR myself.


Discussion:
Hi @Lucidiot. Yep, that plus a test case should do it. 

Thanks for the report! 

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
@@ -344,6 +344,7 @@ def _map_field(self, field):
             serializers.BooleanField: 'boolean',
             serializers.JSONField: 'object',
             serializers.DictField: 'object',
+            serializers.HStoreField: 'object',
         }
         return {'type': FIELD_CLASS_SCHEMA_TYPE.get(field.__class__, '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
@@ -437,6 +437,22 @@ def test_serializer_datefield(self):
         assert properties['date']['format'] == 'date'
         assert properties['datetime']['format'] == 'date-time'
 
+    def test_serializer_hstorefield(self):
+        path = '/'
+        method = 'GET'
+        view = create_view(
+            views.ExampleGenericAPIView,
+            method,
+            create_request(path),
+        )
+        inspector = AutoSchema()
+        inspector.view = view
+
+        responses = inspector._get_responses(path, method)
+        response_schema = responses['200']['content']['application/json']['schema']
+        properties = response_schema['items']['properties']
+        assert properties['hstore']['type'] == 'object'
+
     def test_serializer_validators(self):
         path = '/'
         method = 'GET'
diff --git a/tests/schemas/views.py b/tests/schemas/views.py
--- a/tests/schemas/views.py
+++ b/tests/schemas/views.py
@@ -33,6 +33,7 @@ def get(self, *args, **kwargs):
 class ExampleSerializer(serializers.Serializer):
     date = serializers.DateField()
     datetime = serializers.DateTimeField()
+    hstore = serializers.HStoreField()
 
 
 class ExampleGenericAPIView(generics.GenericAPIView):