manosim / django-rest-framework-docs

Document Web APIs made with Django Rest Framework
https://www.drfdocs.com/
BSD 2-Clause "Simplified" License
647 stars 184 forks source link

Decorator to show fields for api views #161

Open realsby opened 7 years ago

realsby commented 7 years ago

I have a api view. I want to show fields in docs. Do we need a decorator to show fields in docs?

@api_view(['POST'])
@permission_classes((AllowAny, ))
@throttle_classes([AnonRateThrottle])
@api.doc(fields={'email': 'CharField', 'password':'CharField'})
def change_password(request):
    signed_email = request.data.get('email', '')
    password = request.data.get('password', '')

    try:
        email = loads(urlunquote(signed_email))
    except BadSignature:
        return Response(status=status.HTTP_400_BAD_REQUEST)

    if len(password) < 6:
        return Response(status=status.HTTP_400_BAD_REQUEST)

    if not User.objects.filter(username=email):
        return Response(status=status.HTTP_404_NOT_FOUND)

    user = User.objects.get(username=email)
    user.set_password(password)
    user.save()

    return Response(status=status.HTTP_200_OK)