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. What am I doing wrong?
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.