I am trying to hit the api using Django Swagger UI, but I am not getting header in api. I have tried all the answered solutions but I don’t know how none of them worked for me. Please help me to find out what I am doing wrong in.
I am using: drf-spectacular v0.26.2 module.
Here is my api view:
from rest_framework.permissions import IsAuthenticated
from drf_spectacular.utils import extend_schema
from rest_framework.views import APIView
from rest_framework.response import Response
authorization_params_in_header = OpenApiParameter(
"Authorization", OpenApiTypes.STR, OpenApiParameter.HEADER, required=True
)
class ProtectedView(APIView):
permission_classes = (IsAuthenticated,)
@extend_schema(
tags=["Protected"],
parameters=[authorization_params_in_header],
responses={200: "Success"},
)
def get(self, request):
data = {"message": "This is a protected resource"}
return Response(data)
When I hit the api, even if I put header in the field, swagger does not pass it in curl also, which you see in picture below.