Skip to content

Commit e151773

Browse files
committed
Fixed #6856 -- solved a case where generic view delete method generated incorrect OpenAPI response body schema
1 parent f7dc6b5 commit e151773

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

rest_framework/schemas/openapi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ def _get_responses(self, path, method):
485485
else:
486486
response_schema = item_schema
487487

488+
if method == 'DELETE':
489+
return {
490+
'204': {
491+
'description': ''
492+
}
493+
}
494+
488495
return {
489496
'200': {
490497
'content': {

tests/schemas/test_openapi.py

Lines changed: 23 additions & 0 deletions
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)