From a1424675861e6add5a05710fc3a88922e529c340 Mon Sep 17 00:00:00 2001 From: Dima Knivets Date: Fri, 9 Aug 2019 16:02:41 +0300 Subject: [PATCH] Fixed incorrect OpenAPI response schema generation for a DELETE method in generic views (#6860) --- rest_framework/schemas/openapi.py | 7 +++++++ tests/schemas/test_openapi.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index d37148ea2d..0af7510cde 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -465,6 +465,13 @@ def _get_request_body(self, path, method): def _get_responses(self, path, method): # TODO: Handle multiple codes and pagination classes. + if method == 'DELETE': + return { + '204': { + 'description': '' + } + } + item_schema = {} serializer = self._get_serializer(path, method) diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index de8b0f247c..78a5609dac 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -264,6 +264,29 @@ class View(generics.GenericAPIView): }, } + 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}/'