diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index d37148ea2..7b951c6eb 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -485,6 +485,13 @@ class AutoSchema(ViewInspector): else: response_schema = item_schema + if method == 'DELETE': + return { + '204': { + 'description': '' + } + } + return { '200': { 'content': { diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index de8b0f247..78a5609da 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -264,6 +264,29 @@ class TestOperationIntrospection(TestCase): }, } + def test_delete_response_body_generation(self): + """Test that a view's delete method generates a proper response body schema.""" + path = '/{id}/' + method = 'DELETE' + + class View(generics.DestroyAPIView): + serializer_class = views.ExampleSerializer + + view = create_view( + View, + method, + create_request(path), + ) + inspector = AutoSchema() + inspector.view = view + + responses = inspector._get_responses(path, method) + assert responses == { + '204': { + 'description': '', + }, + } + def test_retrieve_response_body_generation(self): """Test that a list of properties is returned for retrieve item views.""" path = '/{id}/'