Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make inflection package truly optional #9303

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/api-guide/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def unicode_http_header(value):
except ImportError:
yaml = None

# inflection is optional
try:
import inflection
except ImportError:
inflection = None


# requests is optional
try:
Expand Down
7 changes: 3 additions & 4 deletions rest_framework/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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

Expand Down Expand Up @@ -247,9 +247,8 @@ def get_operation_id_base(self, path, method, action):
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

Expand Down
Loading