Skip to content

Commit b3f032f

Browse files
peterfarrellcarltongibson
authored andcommitted
Fixed #6875 -- Made OpenAPI Schema operationId casing consistent. (#6876)
1 parent 1cc4be4 commit b3f032f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

rest_framework/schemas/openapi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _get_operation_id(self, path, method):
111111
"""
112112
method_name = getattr(self.view, 'action', method.lower())
113113
if is_list_view(path, method, self.view):
114-
action = 'List'
114+
action = 'list'
115115
elif method_name not in self.method_mapping:
116116
action = method_name
117117
else:
@@ -135,10 +135,13 @@ def _get_operation_id(self, path, method):
135135
name = name[:-7]
136136
elif name.endswith('View'):
137137
name = name[:-4]
138-
if name.endswith(action): # ListView, UpdateAPIView, ThingDelete ...
138+
139+
# Due to camel-casing of classes and `action` being lowercase, apply title in order to find if action truly
140+
# comes at the end of the name
141+
if name.endswith(action.title()): # ListView, UpdateAPIView, ThingDelete ...
139142
name = name[:-len(action)]
140143

141-
if action == 'List' and not name.endswith('s'): # ListThings instead of ListThing
144+
if action == 'list' and not name.endswith('s'): # listThings instead of listThing
142145
name += 's'
143146

144147
return action + name

tests/schemas/test_openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_path_without_parameters(self):
8080

8181
operation = inspector.get_operation(path, method)
8282
assert operation == {
83-
'operationId': 'ListExamples',
83+
'operationId': 'listExamples',
8484
'parameters': [],
8585
'responses': {
8686
'200': {
@@ -402,7 +402,7 @@ def test_operation_id_generation(self):
402402
inspector.view = view
403403

404404
operationId = inspector._get_operation_id(path, method)
405-
assert operationId == 'ListExamples'
405+
assert operationId == 'listExamples'
406406

407407
def test_repeat_operation_ids(self):
408408
router = routers.SimpleRouter()

0 commit comments

Comments
 (0)