So, I have a function-based view on a DRF application that looks something like this:
from rest_framework.decorators import api_view, permission_classes
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
from rest_framework import status
def passcode_generator(callsign: str) -> int:
return 0 # Placeholder
@api_view(["POST"])
@permission_classes([AllowAny])
def get_passcode(request):
callsign = request.data.get("callsign", None)
if callsign is None:
raise Response(
{"error": "Missing callsign"}, status=status.HTTP_400_BAD_REQUEST
)
return Response({"passcode": passcode_generator(callsign)})
Clearly, "callsign" is the only expected argument, and it is mandatory. And that "passcode" is the only field in the response. But DRF doesn't know that.
This means that DRF's web-browsable API page can't show the HTML form tab, and means that documentation generators can't properly document it:
So the question is, how can one document this function-based view?
Thanks!
