From b52462a8d57851314ee097d24622e49287c58277 Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Thu, 5 Sep 2019 18:14:04 +0200 Subject: [PATCH] Set the proper JSON schema type for HStoreFields in OpenAPI schemas --- rest_framework/schemas/openapi.py | 1 + tests/schemas/test_openapi.py | 16 ++++++++++++++++ tests/schemas/views.py | 1 + 3 files changed, 18 insertions(+) diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index ac846bf80..d37070e16 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -344,6 +344,7 @@ class AutoSchema(ViewInspector): serializers.BooleanField: 'boolean', serializers.JSONField: 'object', serializers.DictField: 'object', + serializers.HStoreField: 'object', } return {'type': FIELD_CLASS_SCHEMA_TYPE.get(field.__class__, 'string')} diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index d9375585b..1ebb88261 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -437,6 +437,22 @@ class TestOperationIntrospection(TestCase): 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 index d1fc75eb8..6b83e5bde 100644 --- a/tests/schemas/views.py +++ b/tests/schemas/views.py @@ -33,6 +33,7 @@ class ExampleDetailView(APIView): class ExampleSerializer(serializers.Serializer): date = serializers.DateField() datetime = serializers.DateTimeField() + hstore = serializers.HStoreField() class ExampleGenericAPIView(generics.GenericAPIView):