I have a Settings subclass of APIView which has 2 methods.
class Settings(APIView):
def get(self, request, id=None):
pass
def post(self, request):
pass
In urls.py, I have the following,
urlpatterns = [
path('account/settings/<str:id>', Settings.as_view(http_method_names=['get'])),
path('account/settings/', Settings.as_view(http_method_names=['post'])),
]
As you can see, I want id to be passed as a parameter in get method, but not in post method.
drf-yasg, ideally should only show 2 methods on Swagger page, but it shows 4 methods.
1. GET for /settings/{id}
2. POST for /settings/{id}
3. GET for /settings/
4. POST for /settings/
I have tried adding @action(methods=['GET']), @api_view['GET']. But it doesn't work.
How do I tell drf-yasg to read allowed methods from http_method_names in urls.py.
I can keep the id as optional, and have only one entry in urls.py, but swagger marks it as required on the documentation page.
Also tried but didn't work,
@swagger_auto_schema(methods=['put'], responses=schema_doc)
@swagger_auto_schema(method='get', auto_schema=None)
@api_view(['PUT'])