From e135ea88baddc21c9fc2519adab32b02c0106a33 Mon Sep 17 00:00:00 2001 From: Matt Nawara Date: Fri, 31 Jul 2020 10:38:09 -0400 Subject: [PATCH 1/2] Pluralize list operations ending in y correctly --- rest_framework/schemas/openapi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index 9774a94c76..2126b43ac1 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -241,7 +241,10 @@ def get_operation_id_base(self, path, method, action): name = name[:-len(action)] if action == 'list' and not name.endswith('s'): # listThings instead of listThing - name += 's' + if name.endswith('y'): + name = name[:-1] + 'ies' + else: + name += 's' return name From c0af5ba3b6c6453b7bba2a7a361e164b2a7c5fa2 Mon Sep 17 00:00:00 2001 From: Matt Nawara Date: Fri, 31 Jul 2020 10:42:46 -0400 Subject: [PATCH 2/2] Add test for y -> ies plural endings --- tests/schemas/test_openapi.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index d483f3d456..5f936797f5 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -666,6 +666,21 @@ def test_operation_id_custom_name(self): operationId = inspector.get_operation_id(path, method) assert operationId == 'listUlysses' + def test_operation_id_ies_plural(self): + path = '/' + method = 'GET' + + view = create_view( + views.ExampleGenericAPIView, + method, + create_request(path), + ) + inspector = AutoSchema(operation_id_base='Entry') + inspector.view = view + + operationId = inspector.get_operation_id(path, method) + assert operationId == 'listEntries' + def test_operation_id_override_get(self): class CustomSchema(AutoSchema): def get_operation_id(self, path, method):