swagger_auto_schema add description
To add a description to a Swagger schema using swagger_auto_schema, you can use the description parameter in the decorator. Here's an example:
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
@swagger_auto_schema(
method='get',
operation_description='Get list of all users',
responses={
200: openapi.Response(
description='List of all users',
examples={
'application/json': [
{
'id': 1,
'username': 'johndoe',
'email': 'johndoe@example.com'
},
{
'id': 2,
'username': 'janedoe',
'email': 'janedoe@example.com'
}
]
}
)
}
)
def get_users(request):
# ...
In this example, the operation_description parameter is used to add a description to the operation, and the description parameter is used to add a description to the response. The examples parameter is used to provide an example response for the operation
原文地址: http://www.cveoy.top/t/topic/fHxQ 著作权归作者所有。请勿转载和采集!