Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #6875 - OpenAPI Schema inconsistent operationId casing #6876

Merged
merged 1 commit into from Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions rest_framework/schemas/openapi.py
Expand Up @@ -111,7 +111,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 @@ -135,10 +135,13 @@ def _get_operation_id(self, path, method):
name = name[:-7]
elif name.endswith('View'):
name = name[:-4]
if name.endswith(action): # ListView, UpdateAPIView, ThingDelete ...

# Due to camel-casing of classes and `action` being lowercase, apply title in order to find if action truly
# comes at the end of the name
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
4 changes: 2 additions & 2 deletions tests/schemas/test_openapi.py
Expand Up @@ -80,7 +80,7 @@ def test_path_without_parameters(self):

operation = inspector.get_operation(path, method)
assert operation == {
'operationId': 'ListExamples',
'operationId': 'listExamples',
'parameters': [],
'responses': {
'200': {
Expand Down Expand Up @@ -402,7 +402,7 @@ def test_operation_id_generation(self):
inspector.view = view

operationId = inspector._get_operation_id(path, method)
assert operationId == 'ListExamples'
assert operationId == 'listExamples'

def test_repeat_operation_ids(self):
router = routers.SimpleRouter()
Expand Down