Set the proper JSON schema type for HStoreFields in OpenAPI schemas (#6914)

This commit is contained in:
Erwan Rouchet 2019-10-28 02:13:01 +01:00 committed by Kevin Brown
parent 5ee970c090
commit 39bd6cc5cb
3 changed files with 18 additions and 0 deletions

View File

@ -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')}

View File

@ -462,6 +462,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'

View File

@ -33,6 +33,7 @@ class ExampleDetailView(APIView):
class ExampleSerializer(serializers.Serializer):
date = serializers.DateField()
datetime = serializers.DateTimeField()
hstore = serializers.HStoreField()
class ExampleGenericAPIView(generics.GenericAPIView):