Unlike drf-yasg, which splits docstrings into a summary (first line) and description (remainder), drf-spectacular uses the entire docstring as the operation description.
To achieve the same granular control as drf-yasg, use the summary and description arguments within the @extend_schema decorator. If you want to use a docstring for the description but a custom summary, provide the summary via the decorator and keep the docstring for the description.
For ViewSets where drf-yasg used named sections within a class-level docstring, use @extend_schema_view to apply specific @extend_schema configurations to individual methods.
# Using decorator for explicit summary and description
class UserViewSet(ViewSet):
@extend_schema(
summary="List all the users.",
description="Return a list of all usernames in the system.",
)
def list(self, request):
...
# Using decorator for summary and docstring for description
class UserViewSet(ViewSet):
@extend_schema(summary="List all the users.")
def list(self, request):
"""Return a list of all usernames in the system."""
...
# Replacing class-level docstring sections with @extend_schema_view
@extend_schema_view(
list=extend_schema(
summary="List all the users.",
description="Return a list of all usernames in the system.",
),
retrieve=extend_schema(
summary="Retrieve user",
description="Get details of a specific user",
),
)
class UserViewSet(ViewSet):
...