Closes #9608: Move from drf-yasg to spectacular

Co-authored-by: arthanson <worldnomad@gmail.com>
Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson
2023-03-30 11:32:59 -07:00
committed by GitHub
parent 6fab77d0dd
commit cac9108f5b
35 changed files with 514 additions and 340 deletions

View File

@@ -1,6 +1,8 @@
from django.contrib.auth import authenticate
from django.contrib.auth.models import Group, User
from django.db.models import Count
from drf_spectacular.utils import extend_schema
from drf_spectacular.types import OpenApiTypes
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
@@ -55,9 +57,6 @@ class TokenViewSet(NetBoxModelViewSet):
Limit the non-superusers to their own Tokens.
"""
queryset = super().get_queryset()
# Workaround for schema generation (drf_yasg)
if getattr(self, 'swagger_fake_view', False):
return queryset.none()
if not self.request.user.is_authenticated:
return queryset.none()
if self.request.user.is_superuser:
@@ -71,6 +70,7 @@ class TokenProvisionView(APIView):
"""
permission_classes = []
# @extend_schema(methods=["post"], responses={201: serializers.TokenSerializer})
def post(self, request):
serializer = serializers.TokenProvisionSerializer(data=request.data)
serializer.is_valid()
@@ -93,6 +93,9 @@ class TokenProvisionView(APIView):
return Response(data, status=HTTP_201_CREATED)
def get_serializer_class(self):
return serializers.TokenSerializer
#
# ObjectPermissions
@@ -117,6 +120,7 @@ class UserConfigViewSet(ViewSet):
def get_queryset(self):
return UserConfig.objects.filter(user=self.request.user)
@extend_schema(responses={200: OpenApiTypes.OBJECT})
def list(self, request):
"""
Return the UserConfig for the currently authenticated User.
@@ -125,6 +129,7 @@ class UserConfigViewSet(ViewSet):
return Response(userconfig.data)
@extend_schema(methods=["patch"], responses={201: OpenApiTypes.OBJECT})
def patch(self, request):
"""
Update the UserConfig for the currently authenticated User.