Is there a way to define the object for a post function in the schema of django rest framework?
I have a rest api view:
class DocumentView(viewsets.ModelViewSet):
...
queryset = Document.objects.all().order_by('pk')
serializer_class = serializers.DocumentSerializer
pagination_class = LargeResultPagination
permission_classes = (IsAuthenticated,)
authentication_class = (
Token,
)
def perform_create(self, serializer):
serializer.save(user=self.request.user)
The data that should be posted is of format:
{
"items": ["a", "b", "c"],
"name": "test"
}
How can I describe that in the schema using coreapi?
manual_fields=[
coreapi.Field(
"data",
required=True,
location="body",
description='{"items":[], "name":str}',
schema=coreschema.Object()
),
])
So at least it will be in the description. This of course is not very convinient, especially igf you need more fields in the to-be-posted JSON, since the description is single-line only in swagger.
The most ideal situation would be if I could get the 'items' and the 'name' field as separate fields in the swagger page.
I've googled, but I cannot find an answer for this. Al the examples I saw are for get parameters. So what is best practice here?