Previously, I documented my function-based views like this:
@swagger_auto_schema(
operation_id='ChangePassword',
methods=['POST'],
request_body=ChangePasswordSerializer,
responses={
'200': 'empty response body',
})
def change_password(request):
# code here
We then switched our views to class-based, so I simply copy-pasted the documentation decorator over to the post
method:
class UserChangePasswordView(APIView):
@swagger_auto_schema(
operation_id='ChangePassword',
methods=['POST'],
request_body=ChangePasswordSerializer,
responses={
'200': 'empty response body',
})
def post(self, request):
# code here
However, on running this decorator, drf_yasg
threw the exception
File "/usr/local/lib/python3.6/site-packages/drf_yasg/utils.py", line 126, in decorator
assert all(mth in available_methods for mth in _methods), "http method not bound to view"
What is going on? What does this error message mean?
Note that in source core of drf-yasg
it's mentioned
method
andmethods
are mutually exclusive and must only be present when decorating a view method that more than one HTTP request method.
So methods
would be valid if your UserChangePasswordView.post()
handled more than one method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With