Fix OpenAPI operation name plural appropriately

This commit is contained in:
Shinya Ohyanagi 2021-06-05 00:14:06 +09:00
parent b1004a4733
commit 7cf5c1976b
3 changed files with 19 additions and 2 deletions

View File

@ -3,6 +3,7 @@ coreapi==2.3.1
coreschema==0.0.4
django-filter>=2.4.0,<3.0
django-guardian>=2.4.0,<2.5
inflection==0.5.1
markdown==3.3;python_version>="3.6"
markdown==3.2.2;python_version=="3.5"
psycopg2-binary>=2.8.5,<2.9

View File

@ -11,6 +11,7 @@ from django.core.validators import (
)
from django.db import models
from django.utils.encoding import force_str
from inflection import pluralize
from rest_framework import (
RemovedInDRF314Warning, exceptions, renderers, serializers
@ -247,8 +248,8 @@ class AutoSchema(ViewInspector):
if name.endswith(action.title()): # ListView, UpdateAPIView, ThingDelete ...
name = name[:-len(action)]
if action == 'list' and not name.endswith('s'): # listThings instead of listThing
name += 's'
if action == 'list':
name = pluralize(name)
return name

View File

@ -695,6 +695,21 @@ class TestOperationIntrospection(TestCase):
operationId = inspector.get_operation_id(path, method)
assert operationId == 'listUlysses'
def test_operation_id_plural(self):
path = '/'
method = 'GET'
view = create_view(
views.ExampleGenericAPIView,
method,
create_request(path),
)
inspector = AutoSchema(operation_id_base='City')
inspector.view = view
operationId = inspector.get_operation_id(path, method)
assert operationId == 'listCities'
def test_operation_id_override_get(self):
class CustomSchema(AutoSchema):
def get_operation_id(self, path, method):