diff --git a/docs/api-guide/schemas.md b/docs/api-guide/schemas.md index 7af98dbf5..c387af972 100644 --- a/docs/api-guide/schemas.md +++ b/docs/api-guide/schemas.md @@ -56,10 +56,11 @@ The following sections explain more. ### Install dependencies - pip install pyyaml uritemplate + pip install pyyaml uritemplate inflection * `pyyaml` is used to generate schema into YAML-based OpenAPI format. * `uritemplate` is used internally to get parameters in path. +* `inflection` is used to pluralize operations more appropriately in the list endpoints. ### Generating a static schema with the `generateschema` management command diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 472b8ad24..afc06b6cb 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -46,6 +46,12 @@ try: except ImportError: yaml = None +# inflection is optional +try: + import inflection +except ImportError: + inflection = None + # requests is optional try: diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index c154494e2..38031e646 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -14,7 +14,7 @@ from django.utils.encoding import force_str from rest_framework import ( RemovedInDRF315Warning, exceptions, renderers, serializers ) -from rest_framework.compat import uritemplate +from rest_framework.compat import inflection, uritemplate from rest_framework.fields import _UnvalidatedField, empty from rest_framework.settings import api_settings @@ -247,9 +247,8 @@ class AutoSchema(ViewInspector): name = name[:-len(action)] if action == 'list': - from inflection import pluralize - - name = pluralize(name) + assert inflection, '`inflection` must be installed for OpenAPI schema support.' + name = inflection.pluralize(name) return name