Skip to content

Commit 2a00454

Browse files
committed
Merge pull request encode#2 from nschlemm/issue-192-expose-fields-for-options
Issue 192 expose fields for options
2 parents 08e9e20 + b07cfdc commit 2a00454

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

rest_framework/tests/generics.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,25 @@ def test_options_root_view(self):
125125
'actions': {}
126126
}
127127
# TODO: this is just a draft for fields' metadata - needs review and decision
128-
for method in ('GET', 'POST',):
129-
expected['actions'][method] = {
130-
'text': {
131-
# TODO add help_text and label when they are available
132-
#'help_text': '',
133-
#'label': None,
134-
'read_only': False,
135-
'required': True,
136-
'type': 'Single Character',
137-
},
138-
'id': {
139-
# TODO add help_text and label when they are available
140-
#'help_text': '',
141-
#'label': None,
142-
'read_only': True,
143-
'required': False,
144-
'type': 'Integer',
145-
},
146-
}
128+
expected['actions']['GET'] = {}
129+
expected['actions']['POST'] = {
130+
'text': {
131+
# TODO add help_text and label when they are available
132+
#'help_text': '',
133+
#'label': None,
134+
'read_only': False,
135+
'required': True,
136+
'type': 'Single Character',
137+
},
138+
'id': {
139+
# TODO add help_text and label when they are available
140+
#'help_text': '',
141+
#'label': None,
142+
'read_only': True,
143+
'required': False,
144+
'type': 'Integer',
145+
},
146+
}
147147
self.assertEqual(response.status_code, status.HTTP_200_OK)
148148
self.assertEqual(response.data, expected)
149149

@@ -263,7 +263,9 @@ def test_options_instance_view(self):
263263
'actions': {}
264264
}
265265
# TODO: this is just a draft idea for fields' metadata - needs review and decision
266-
for method in ('GET', 'PATCH', 'PUT', 'DELETE'):
266+
for method in ('GET', 'DELETE'):
267+
expected['actions'][method] = {}
268+
for method in ('PATCH', 'PUT'):
267269
expected['actions'][method] = {
268270
'text': {
269271
# TODO uncomment label and description when they are

rest_framework/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ def _generate_action_metadata(self, request):
7979
try:
8080
self.check_permissions(cloned_request)
8181

82+
# TODO: discuss whether and how to expose parameters like e.g. filter or paginate
83+
if method in ('GET', 'DELETE'):
84+
actions[method] = {}
85+
continue
86+
8287
# TODO: find right placement - APIView does not have get_serializer
88+
if not hasattr(self, 'get_serializer'):
89+
continue
8390
serializer = self.get_serializer()
8491
if serializer is not None:
8592
field_name_types = {}

0 commit comments

Comments
 (0)