Skip to content

Commit

Permalink
Use _get_serializer() in _get_operation_id()
Browse files Browse the repository at this point in the history
Also, capitalize `list` action to be in sync with `method_mapping`
  • Loading branch information
domingues committed Jan 24, 2020
1 parent e4a26ad commit 338f059
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rest_framework/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _get_operation_id(self, path, method):
"""
method_name = getattr(self.view, 'action', method.lower())
if is_list_view(path, method, self.view):
action = 'list'
action = 'List'
elif method_name not in self.method_mapping:
action = method_name
else:
Expand All @@ -117,8 +117,8 @@ def _get_operation_id(self, path, method):
name = model.__name__

# Try with the serializer class name
elif hasattr(self.view, 'get_serializer_class'):
name = self.view.get_serializer_class().__name__
elif self._get_serializer(path, method) is not None:
name = self._get_serializer(path, method).__class__.__name__
if name.endswith('Serializer'):
name = name[:-10]

Expand All @@ -135,7 +135,7 @@ def _get_operation_id(self, path, method):
if name.endswith(action.title()): # ListView, UpdateAPIView, ThingDelete ...
name = name[:-len(action)]

if action == 'list' and not name.endswith('s'): # listThings instead of listThing
if action == 'List' and not name.endswith('s'): # listThings instead of listThing
name += 's'

return action + name
Expand Down

0 comments on commit 338f059

Please sign in to comment.