I have the following problem, which has been difficult for me to find documentation on function-based views to document them with drf_spectacular
since all this is found for class-based views
I have tried different ways to document the requestBody
in swagger using serializers_class
, manual objects, inline_serializers
but all this without any success, here I leave a fragment of my code and a screenshot of how it should be and where should I be
@extend_schema(
summary="Fetch order information",
description="This endpoint filter orders based on the provided parameters.",
tags=["orders"],
request=OrderInfoParamsSerializer, # HERE IS MY PROBLEM
responses={
200: OrderInfoSerializer(many=True),
},
)
@extend_schema(request=None)
@api_view(["GET"])
@token_required
def order_info(request: Request) -> Response:
params = OrderInfoParamsSerializer(data=request.data)
if not params.is_valid():
return Response({"error": params.errors}, status=status.HTTP_400_BAD_REQUEST)
params = params.validated_data
...
class OrderInfoParamsSerializer(serializers.Serializer):
order_id = serializers.IntegerField(
required=False, allow_null=True, help_text="Filter by order ID"
)
class OrderInfoSerializer(serializers.ModelSerializer):
class Meta:
model = Orders
fields = "__all__"
I tried to migrate the views to those based on classes where it only worked with one in the POST method not with the GET (I could migrate all my views if this worked)
I didn’t want to have to refactor the entire project and would like to be able to find some solution that works for function-based views.