mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-16 19:22:24 +03:00
parent
337ba211e8
commit
4dcfc8c647
|
@ -56,10 +56,11 @@ The following sections explain more.
|
||||||
|
|
||||||
### Install dependencies
|
### Install dependencies
|
||||||
|
|
||||||
pip install pyyaml uritemplate
|
pip install pyyaml uritemplate inflection
|
||||||
|
|
||||||
* `pyyaml` is used to generate schema into YAML-based OpenAPI format.
|
* `pyyaml` is used to generate schema into YAML-based OpenAPI format.
|
||||||
* `uritemplate` is used internally to get parameters in path.
|
* `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
|
### Generating a static schema with the `generateschema` management command
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,15 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
yaml = None
|
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
|
# requests is optional
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -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 uritemplate
|
from rest_framework.compat import pluralize, 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,8 +247,6 @@ class AutoSchema(ViewInspector):
|
||||||
name = name[:-len(action)]
|
name = name[:-len(action)]
|
||||||
|
|
||||||
if action == 'list':
|
if action == 'list':
|
||||||
from inflection import pluralize
|
|
||||||
|
|
||||||
name = pluralize(name)
|
name = pluralize(name)
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
Loading…
Reference in New Issue
Block a user