diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index 1d0ec35d5..088f792c4 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -185,6 +185,10 @@ class AutoSchema(ViewInspector): """ Return components with their properties from the serializer. """ + + if method.lower() == 'delete': + return {} + serializer = self._get_serializer(path, method) if not isinstance(serializer, serializers.Serializer): diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index c9f6d967e..43101635d 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -1087,3 +1087,15 @@ class TestGenerator(TestCase): assert 'components' in schema assert 'schemas' in schema['components'] assert 'Duplicate' in schema['components']['schemas'] + + def test_component_should_not_be_generated_for_delete_method(self): + class ExampleView(generics.DestroyAPIView): + schema = AutoSchema(operation_id_base='example') + + url_patterns = [ + url(r'^example/?$', ExampleView.as_view()), + ] + generator = SchemaGenerator(patterns=url_patterns) + schema = generator.get_schema(request=create_request('/')) + assert 'components' not in schema + assert 'content' not in schema['paths']['/example/']['delete']['responses']['204']