How to add a schema under actions in django_rest_framework

`@api_view(['POST'])
def createUser(request):

    print(to_jsonschema(UserSerializer()))

    serializer = UserSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=201)
    else:
        return Response(serializer.errors, status=400)`

For example I would like for this to be returned

{
  "name": "Token Refresh",
  "description": "Takes a refresh type JSON web token and returns an access type JSON web\ntoken if the refresh token is valid.",
  "renders": ["application/json", "text/html"],
  "parses": [
    "application/json",
    "application/x-www-form-urlencoded",
    "multipart/form-data"
  ],
  "actions": {
    "POST": {
      "refresh": {
        "type": "string",
        "required": true,
        "read_only": false,
        "label": "Refresh"
      },
      "access": {
        "type": "string",
        "required": false,
        "read_only": true,
        "label": "Access"
      }
    }
  }
}

This is from an built in view from rest_framework_simplejwt. Overall I would like to add a schema such as the actions data which shows for the method post refresh and access are required. I want something like this for my createUser view as I can easily see what attribute the api endpoint takes for example username or password,

I looked online and found this https://www.django-rest-framework.org/api-guide/metadata/ but I couldn't get it to work. I looked at other solutions also but they were just showing to create a different view which sends a JSON schema back as get request. Overall I just want something simple that I can easily use to communicate with my backend without having to go look at my backend code to see what values this view takes for its Serializer.

Back to Top