Skip to content

Commit 41f27c3

Browse files
authored
Schemas: Don't generate component for DELETE method. (#7229)
1 parent e6c1afb commit 41f27c3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

rest_framework/schemas/openapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ def get_components(self, path, method):
185185
"""
186186
Return components with their properties from the serializer.
187187
"""
188+
189+
if method.lower() == 'delete':
190+
return {}
191+
188192
serializer = self._get_serializer(path, method)
189193

190194
if not isinstance(serializer, serializers.Serializer):

tests/schemas/test_openapi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,3 +1087,15 @@ def test_duplicate_component_name(self):
10871087
assert 'components' in schema
10881088
assert 'schemas' in schema['components']
10891089
assert 'Duplicate' in schema['components']['schemas']
1090+
1091+
def test_component_should_not_be_generated_for_delete_method(self):
1092+
class ExampleView(generics.DestroyAPIView):
1093+
schema = AutoSchema(operation_id_base='example')
1094+
1095+
url_patterns = [
1096+
url(r'^example/?$', ExampleView.as_view()),
1097+
]
1098+
generator = SchemaGenerator(patterns=url_patterns)
1099+
schema = generator.get_schema(request=create_request('/'))
1100+
assert 'components' not in schema
1101+
assert 'content' not in schema['paths']['/example/']['delete']['responses']['204']

0 commit comments

Comments
 (0)