mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Fix OpenAPI operation name plural appropriately (#8017)
This commit is contained in:
parent
ebde56b932
commit
9e328a9549
|
@ -3,6 +3,7 @@ coreapi==2.3.1
|
||||||
coreschema==0.0.4
|
coreschema==0.0.4
|
||||||
django-filter>=2.4.0,<3.0
|
django-filter>=2.4.0,<3.0
|
||||||
django-guardian>=2.4.0,<2.5
|
django-guardian>=2.4.0,<2.5
|
||||||
|
inflection==0.5.1
|
||||||
markdown==3.3
|
markdown==3.3
|
||||||
psycopg2-binary>=2.9.5,<2.10
|
psycopg2-binary>=2.9.5,<2.10
|
||||||
pygments==2.12
|
pygments==2.12
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.core.validators import (
|
||||||
)
|
)
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
|
from inflection import pluralize
|
||||||
|
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
RemovedInDRF315Warning, exceptions, renderers, serializers
|
RemovedInDRF315Warning, exceptions, renderers, serializers
|
||||||
|
@ -247,8 +248,8 @@ class AutoSchema(ViewInspector):
|
||||||
if name.endswith(action.title()): # ListView, UpdateAPIView, ThingDelete ...
|
if name.endswith(action.title()): # ListView, UpdateAPIView, ThingDelete ...
|
||||||
name = name[:-len(action)]
|
name = name[:-len(action)]
|
||||||
|
|
||||||
if action == 'list' and not name.endswith('s'): # listThings instead of listThing
|
if action == 'list':
|
||||||
name += 's'
|
name = pluralize(name)
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
|
@ -715,6 +715,21 @@ class TestOperationIntrospection(TestCase):
|
||||||
operationId = inspector.get_operation_id(path, method)
|
operationId = inspector.get_operation_id(path, method)
|
||||||
assert operationId == 'listUlysses'
|
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):
|
def test_operation_id_override_get(self):
|
||||||
class CustomSchema(AutoSchema):
|
class CustomSchema(AutoSchema):
|
||||||
def get_operation_id(self, path, method):
|
def get_operation_id(self, path, method):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user