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 1 commit
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
9 changes: 9 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def unicode_http_header(value):
except ImportError:
yaml = None

# inflection is optional
try:
from inflection import pluralize
except ImportError:
def pluralize(text):
if not text.endswith('s'):
text += "s"
return text


# requests is optional
try:
Expand Down
4 changes: 1 addition & 3 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 pluralize, uritemplate
from rest_framework.fields import _UnvalidatedField, empty
from rest_framework.settings import api_settings

Expand Down Expand Up @@ -247,8 +247,6 @@ def get_operation_id_base(self, path, method, action):
name = name[:-len(action)]

if action == 'list':
from inflection import pluralize

name = pluralize(name)

return name
Expand Down
Loading