Hi,

Reached out to Tom on Twitter and was forwarded here: 
https://twitter.com/_tomchristie/status/938491963040501761

Could be related to:
https://groups.google.com/forum/?fromgroups#!searchin/django-rest-framework/schema%7Csort:date/django-rest-framework/8QQjXuEX8AA/zH1wpdOiBwAJ
https://groups.google.com/forum/?fromgroups#!searchin/django-rest-framework/schema|sort:date/django-rest-framework/b6wgkBLNdZ4/V-2dpYwLBgAJ

I would like to add schema documentation for a custom method on a 
ModelViewSet (*for drf-openapi*), i.e.:

class DiscussionViewSet(ModelViewSet):
   serializer = DiscussionSerializer
   queryset = Discussion.objects.all()

   def vote(self, request, version, pk):
       discussion = self.get_queryset().get()
       vote_type = request.POST.get('vote_type')
       if vote_type in ['up', 'down']:
           discussion.vote(vote_type)
       return self.get_serializer(discussion)

Something to note:

   - I am using nested routes (that code is omitted), but I don't think 
   that has anything to do with my issue.

If I wrap the `vote` in a `detail_route` decorator, it will show in my 
schema endpoint, but uses the values of my DiscussionSerializer for the 
request body (see attachment)

I've tried using the `schema` decorator and using AutoSchema() directly 
passing `manual_fields`, I've also tried overriding the `schema` on the 
ViewSet itself the same way:

schema = AutoSchema(manual_fields=[
        coreapi.Field(
            'vote_type',
            required=True,
            location='body',
            schema=coreschema.String(
                title='vote_type',
                description='up or down')
        )
    ])


If I DON'T use `detail_route` and only use `api_view` decorator, my 
endpoint fails to show in the schema at all.

Help is greatly appreciated as I've spent a good two days trying different 
things and searching around the internet for an answer.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to