Make inflection compat layer consistent with the others

Co-authored-by: T. Franzel <13507857+tfranzel@users.noreply.github.com>
This commit is contained in:
Bruno Alla 2024-03-18 22:14:05 +00:00
parent 4dcfc8c647
commit 492529006d
No known key found for this signature in database
2 changed files with 5 additions and 7 deletions

View File

@ -48,12 +48,9 @@ except ImportError:
# inflection is optional # inflection is optional
try: try:
from inflection import pluralize import inflection
except ImportError: except ImportError:
def pluralize(text): inflection = None
if not text.endswith('s'):
text += "s"
return text
# requests is optional # requests is optional

View File

@ -14,7 +14,7 @@ from django.utils.encoding import force_str
from rest_framework import ( from rest_framework import (
RemovedInDRF315Warning, exceptions, renderers, serializers RemovedInDRF315Warning, exceptions, renderers, serializers
) )
from rest_framework.compat import pluralize, uritemplate from rest_framework.compat import inflection, uritemplate
from rest_framework.fields import _UnvalidatedField, empty from rest_framework.fields import _UnvalidatedField, empty
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -247,7 +247,8 @@ class AutoSchema(ViewInspector):
name = name[:-len(action)] name = name[:-len(action)]
if action == 'list': if action == 'list':
name = pluralize(name) assert inflection, '`inflection` must be installed for OpenAPI schema support.'
name = inflection.pluralize(name)
return name return name