因此,我正在使用以下代码记录以下代码drf-spectacular
:
from rest_framework import response
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
from drf_spectacular.utils import extend_schema, OpenApiParameter
def passcode_generator:
return 0 # placeholder
@extend_schema(
parameters=[
OpenApiParameter(name="callsign", required=True, type=str),
],
description="Get an APRS-IS passcode for a given callsign",
)
@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)})
我不明白该怎么做是如何记录响应。OpenApiResponse
即,有drf_spectacular.utils
但文档很薄。我如何用这个系统记录我的 API 的响应?