1๐
Try to use drf_yasg
instead, Swagger will generate the documentation for APIs, but itโs not absolutely right!
If you want to correct Swagger documentation, you can do it. You will need to use swagger_auto_schema
decorator. Below is the sample code:
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
class ProductSuspendView(CreateAPIView):
@swagger_auto_schema(
tags=['dashboard'],
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'id': openapi.Schema(
type=openapi.TYPE_INTEGER,
description='Id',
),
'suspend_kinds': openapi.Schema(
type=openapi.TYPE_ARRAY,
items=openapi.Items(type=openapi.TYPE_INTEGER),
description='Array suspend (Inappropriate image: 1, Insufficient information: 2, Bad language: 3) (suspend_kinds=[1,2])'
),
}
),
responses={
status.HTTP_200_OK: SuccessResponseSerializer,
status.HTTP_400_BAD_REQUEST: ErrorResponseSerializer
}
)
def post(self, request, *args, **kwargs):
"""
Suspend a product.
"""
...
if success:
return Response({'success': True}, status.HTTP_200_OK)
return Response({'success': False}, status.HTTP_400_BAD_REQUEST)
๐คVu Phan
1๐
Using https://drf-spectacular.readthedocs.io/en/latest/ would be the right choice for this use case now. this is well maintained and support OpenAPI 3.0+. also it is now suggested by django-rest-framework itself.
๐คauvipy
- Uwsgi http is ambiguous
- Why does Django use tuples for settings and not lists?
- Django: default language i18n
0๐
1. of everything please use drf-yasg for documentation .
2. you can find its implementation in one of my repository Kirpi and learn how to use that.
3. if you in 3. ; have question,let me know.
๐คHamed Rostami
- Indirect inline in Django admin
- Proper declaration of an empty Django PostgreSQL JSONField default value in migration file
- NoReverseMatch on password_Reset_confirm
- What is the different between the get logger functions from celery.utils.log and logging?
- Django queryset __contains case sensitive?
Source:stackexchange.com