mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Don't show hidden fields in metadata (#5854)
HiddenField is meant to be hidden, but we discovered it showing up in OPTIONS requests
This commit is contained in:
parent
a7e2a7bfcd
commit
a5072778e9
|
@ -111,6 +111,7 @@ class SimpleMetadata(BaseMetadata):
|
|||
return OrderedDict([
|
||||
(field_name, self.get_field_info(field))
|
||||
for field_name, field in serializer.fields.items()
|
||||
if not isinstance(field, serializers.HiddenField)
|
||||
])
|
||||
|
||||
def get_field_info(self, field):
|
||||
|
|
|
@ -275,6 +275,27 @@ class TestMetadata:
|
|||
view = ExampleView.as_view(versioning_class=scheme)
|
||||
view(request=request)
|
||||
|
||||
def test_dont_show_hidden_fields(self):
|
||||
"""
|
||||
HiddenField shouldn't show up in SimpleMetadata at all.
|
||||
"""
|
||||
class ExampleSerializer(serializers.Serializer):
|
||||
integer_field = serializers.IntegerField(max_value=10)
|
||||
hidden_field = serializers.HiddenField(default=1)
|
||||
|
||||
class ExampleView(views.APIView):
|
||||
"""Example view."""
|
||||
def post(self, request):
|
||||
pass
|
||||
|
||||
def get_serializer(self):
|
||||
return ExampleSerializer()
|
||||
|
||||
view = ExampleView.as_view()
|
||||
response = view(request=request)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert set(response.data['actions']['POST'].keys()) == {'integer_field'}
|
||||
|
||||
def test_list_serializer_metadata_returns_info_about_fields_of_child_serializer(self):
|
||||
class ExampleSerializer(serializers.Serializer):
|
||||
integer_field = serializers.IntegerField(max_value=10)
|
||||
|
|
Loading…
Reference in New Issue
Block a user