diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index f5a0c3579..7c9efc4d1 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -9,6 +9,7 @@ used to annotate methods on viewsets that should be included by routers. from __future__ import unicode_literals import types +import warnings from django.utils import six @@ -76,9 +77,11 @@ def api_view(http_method_names=None, exclude_from_schema=False): APIView.schema) if exclude_from_schema: - # This won't catch an explicit `exclude_from_schema=False` - # but it should be good enough. - # TODO: DeprecationWarning + warnings.warn( + "The `exclude_from_schema` argument to `api_view` is deprecated. " + "Use the `schema` decorator instead, passing `None`.", + PendingDeprecationWarning + ) WrappedAPIView.exclude_from_schema = exclude_from_schema return WrappedAPIView.as_view() diff --git a/rest_framework/schemas/generators.py b/rest_framework/schemas/generators.py index 21726ef26..f24fdaafd 100644 --- a/rest_framework/schemas/generators.py +++ b/rest_framework/schemas/generators.py @@ -3,6 +3,7 @@ generators.py # Top-down schema generation See schemas.__init__.py for package overview. """ +import warnings from collections import OrderedDict from importlib import import_module @@ -149,7 +150,10 @@ class EndpointEnumerator(object): return False # Ignore anything except REST framework views. if hasattr(callback.cls, 'exclude_from_schema'): - # TODO: deprecation warning + fmt = ("{}. The `APIView.exclude_from_schema` is deprecated. " + "Set `schema = None` instead") + msg = fmt.format(callback.cls.__name__) + warnings.warn(msg, PendingDeprecationWarning) if getattr(callback.cls, 'exclude_from_schema', False): return False diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 1ecd31314..90916fdf5 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -641,9 +641,9 @@ def included_fbv(request): class SchemaGenerationExclusionTests(TestCase): def setUp(self): self.patterns = [ - url('^excluded-cbv/?$', ExcludedAPIView.as_view()), - url('^excluded-fbv/?$', excluded_fbv), - url('^included-fbv/?$', included_fbv), + url('^excluded-cbv/$', ExcludedAPIView.as_view()), + url('^excluded-fbv/$', excluded_fbv), + url('^included-fbv/$', included_fbv), ] def test_schema_generator_excludes_correctly(self): @@ -690,4 +690,21 @@ class SchemaGenerationExclusionTests(TestCase): assert should_include == expected def test_deprecations(self): - pass + with pytest.warns(PendingDeprecationWarning): + @api_view(["GET"], exclude_from_schema=True) + def view(request): + pass + + class OldFashjonedExcludedView(APIView): + exclude_from_schema = True + + def get(self, request, *args, **kwargs): + pass + + patterns = [ + url('^excluded-old-fashioned/$', OldFashjonedExcludedView.as_view()), + ] + + inspector = EndpointEnumerator(patterns) + with pytest.warns(PendingDeprecationWarning): + inspector.get_api_endpoints()