From d0ed482d7094e94b8cbfdc6c0f8335e02d79b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Mon, 22 Aug 2016 11:53:53 -0400 Subject: [PATCH] Skip HiddenField from Schema fields (#4429) --- rest_framework/schemas.py | 3 ++- tests/test_schemas.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index c9834c64d..1b899450f 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -296,8 +296,9 @@ class SchemaGenerator(object): fields = [] for field in serializer.fields.values(): - if field.read_only: + if field.read_only or isinstance(field, serializers.HiddenField): continue + required = field.required and method != 'PATCH' description = force_text(field.help_text) if field.help_text else '' field = coreapi.Field( diff --git a/tests/test_schemas.py b/tests/test_schemas.py index c866e09be..197e62eb0 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -26,6 +26,8 @@ class ExamplePagination(pagination.PageNumberPagination): class ExampleSerializer(serializers.Serializer): a = serializers.CharField(required=True, help_text='A field description') b = serializers.CharField(required=False) + read_only = serializers.CharField(read_only=True) + hidden = serializers.HiddenField(default='hello') class AnotherSerializer(serializers.Serializer):