我使用 drf-yasg 为Django REST API生成大量文档。我有两个端点,分别是带有GET,POST和DELETE方法的 items / ;和 items /
这是我在urls.py中的片段:
urlpatters = [
url(r'^items/$', views.ItemViewSet.as_view()),
path('items/<uuid:itemID>', views.ItemViewSet.as_view()),
]
views.py包含以下内容:
class ItemViewSet(mixins.DestroyModelMixin, GenericAPIView):
def get(self, request):
# ...
return Response(HTTP_200_OK)
def post(self, request):
# ...
return Response(status=status.HTTP_201_CREATED)
def delete(self, request, itemID):
# ...
return Response(status=status.HTTP_204_NO_CONTENT)
def delete(self, request):
# ...
return Response(status=status.HTTP_204_NO_CONTENT)
如何从 items /
我已阅读https://github.com/axnsan12/drf-yasg/blob/master/docs/custom_spec.rst,并 Exclude URLs from Django REST Swagger,但尚未找到可行的解决方案。
答案 0 :(得分:0)
您可以通过在views.py
中设置swagger_schema = None
来从文档中排除API端点。
class MyView(generics.ListCreateAPIView):
"""MyView class doc."""
swagger_schema = None
def get(self, response):
# Do stuff here
来源:https://github.com/axnsan12/drf-yasg/commit/a211184478e6f0ca348312438c9c29d7b535b0fa