Schemas: Don't generate component for DELETE method. (#7229)

This commit is contained in:
Dhaval Mehta 2020-04-09 22:40:50 +05:30 committed by GitHub
parent e6c1afbcf9
commit 41f27c3b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -185,6 +185,10 @@ class AutoSchema(ViewInspector):
""" """
Return components with their properties from the serializer. Return components with their properties from the serializer.
""" """
if method.lower() == 'delete':
return {}
serializer = self._get_serializer(path, method) serializer = self._get_serializer(path, method)
if not isinstance(serializer, serializers.Serializer): if not isinstance(serializer, serializers.Serializer):

View File

@ -1087,3 +1087,15 @@ class TestGenerator(TestCase):
assert 'components' in schema assert 'components' in schema
assert 'schemas' in schema['components'] assert 'schemas' in schema['components']
assert 'Duplicate' in schema['components']['schemas'] assert 'Duplicate' in schema['components']['schemas']
def test_component_should_not_be_generated_for_delete_method(self):
class ExampleView(generics.DestroyAPIView):
schema = AutoSchema(operation_id_base='example')
url_patterns = [
url(r'^example/?$', ExampleView.as_view()),
]
generator = SchemaGenerator(patterns=url_patterns)
schema = generator.get_schema(request=create_request('/'))
assert 'components' not in schema
assert 'content' not in schema['paths']['/example/']['delete']['responses']['204']