mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-30 18:33:21 +03:00
Removed exclude_from_schema per deprecation policy.
This commit is contained in:
parent
5627d91ee9
commit
7fb11bf2f5
|
@ -17,7 +17,7 @@ from django.utils import six
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
|
||||||
def api_view(http_method_names=None, exclude_from_schema=False):
|
def api_view(http_method_names=None):
|
||||||
"""
|
"""
|
||||||
Decorator that converts a function-based view into an APIView subclass.
|
Decorator that converts a function-based view into an APIView subclass.
|
||||||
Takes a list of allowed methods for the view as an argument.
|
Takes a list of allowed methods for the view as an argument.
|
||||||
|
@ -77,15 +77,8 @@ def api_view(http_method_names=None, exclude_from_schema=False):
|
||||||
WrappedAPIView.schema = getattr(func, 'schema',
|
WrappedAPIView.schema = getattr(func, 'schema',
|
||||||
APIView.schema)
|
APIView.schema)
|
||||||
|
|
||||||
if exclude_from_schema:
|
|
||||||
warnings.warn(
|
|
||||||
"The `exclude_from_schema` argument to `api_view` is deprecated. "
|
|
||||||
"Use the `schema` decorator instead, passing `None`.",
|
|
||||||
DeprecationWarning
|
|
||||||
)
|
|
||||||
WrappedAPIView.exclude_from_schema = exclude_from_schema
|
|
||||||
|
|
||||||
return WrappedAPIView.as_view()
|
return WrappedAPIView.as_view()
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -207,14 +207,6 @@ class EndpointEnumerator(object):
|
||||||
if not is_api_view(callback):
|
if not is_api_view(callback):
|
||||||
return False # Ignore anything except REST framework views.
|
return False # Ignore anything except REST framework views.
|
||||||
|
|
||||||
if hasattr(callback.cls, 'exclude_from_schema'):
|
|
||||||
fmt = ("The `{}.exclude_from_schema` attribute is deprecated. "
|
|
||||||
"Set `schema = None` instead.")
|
|
||||||
msg = fmt.format(callback.cls.__name__)
|
|
||||||
warnings.warn(msg, DeprecationWarning)
|
|
||||||
if getattr(callback.cls, 'exclude_from_schema', False):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if callback.cls.schema is None:
|
if callback.cls.schema is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -1032,38 +1032,6 @@ class SchemaGenerationExclusionTests(TestCase):
|
||||||
|
|
||||||
assert should_include == expected
|
assert should_include == expected
|
||||||
|
|
||||||
def test_deprecations(self):
|
|
||||||
with pytest.warns(DeprecationWarning) as record:
|
|
||||||
@api_view(["GET"], exclude_from_schema=True)
|
|
||||||
def view(request):
|
|
||||||
pass
|
|
||||||
|
|
||||||
assert len(record) == 1
|
|
||||||
assert str(record[0].message) == (
|
|
||||||
"The `exclude_from_schema` argument to `api_view` is deprecated. "
|
|
||||||
"Use the `schema` decorator instead, passing `None`."
|
|
||||||
)
|
|
||||||
|
|
||||||
class OldFashionedExcludedView(APIView):
|
|
||||||
exclude_from_schema = True
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
patterns = [
|
|
||||||
url('^excluded-old-fashioned/$', OldFashionedExcludedView.as_view()),
|
|
||||||
]
|
|
||||||
|
|
||||||
inspector = EndpointEnumerator(patterns)
|
|
||||||
with pytest.warns(DeprecationWarning) as record:
|
|
||||||
inspector.get_api_endpoints()
|
|
||||||
|
|
||||||
assert len(record) == 1
|
|
||||||
assert str(record[0].message) == (
|
|
||||||
"The `OldFashionedExcludedView.exclude_from_schema` attribute is "
|
|
||||||
"deprecated. Set `schema = None` instead."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@api_view(["GET"])
|
@api_view(["GET"])
|
||||||
def simple_fbv(request):
|
def simple_fbv(request):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user