Skip to content

Commit a142467

Browse files
knivetscarltongibson
authored andcommitted
Fixed incorrect OpenAPI response schema generation for a DELETE method in generic views (#6860)
1 parent f7dc6b5 commit a142467

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

rest_framework/schemas/openapi.py

+7
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ def _get_request_body(self, path, method):
465465

466466
def _get_responses(self, path, method):
467467
# TODO: Handle multiple codes and pagination classes.
468+
if method == 'DELETE':
469+
return {
470+
'204': {
471+
'description': ''
472+
}
473+
}
474+
468475
item_schema = {}
469476
serializer = self._get_serializer(path, method)
470477

tests/schemas/test_openapi.py

+23
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,29 @@ class View(generics.GenericAPIView):
264264
},
265265
}
266266

267+
def test_delete_response_body_generation(self):
268+
"""Test that a view's delete method generates a proper response body schema."""
269+
path = '/{id}/'
270+
method = 'DELETE'
271+
272+
class View(generics.DestroyAPIView):
273+
serializer_class = views.ExampleSerializer
274+
275+
view = create_view(
276+
View,
277+
method,
278+
create_request(path),
279+
)
280+
inspector = AutoSchema()
281+
inspector.view = view
282+
283+
responses = inspector._get_responses(path, method)
284+
assert responses == {
285+
'204': {
286+
'description': '',
287+
},
288+
}
289+
267290
def test_retrieve_response_body_generation(self):
268291
"""Test that a list of properties is returned for retrieve item views."""
269292
path = '/{id}/'

0 commit comments

Comments
 (0)