mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +03:00
Export the docstring of the method in the Link description
For viewset, it exports the corresponding action (list, retrieve, update, etc.). For simple APIView, it returns the http handler (get, post, put, etc.).
This commit is contained in:
parent
99aa001f10
commit
38b953bb7e
|
@ -6,7 +6,7 @@ from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
|
|||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from rest_framework import exceptions, serializers
|
||||
from rest_framework import exceptions, serializers, viewsets
|
||||
from rest_framework.compat import coreapi, uritemplate, urlparse
|
||||
from rest_framework.request import clone_request
|
||||
from rest_framework.views import APIView
|
||||
|
@ -207,10 +207,18 @@ class SchemaGenerator(object):
|
|||
else:
|
||||
encoding = None
|
||||
|
||||
if isinstance(view, viewsets.GenericViewSet):
|
||||
actions = getattr(callback, 'actions', self.default_mapping)
|
||||
action = actions[method.lower()]
|
||||
view_fn = getattr(callback.cls, action, None)
|
||||
else:
|
||||
view_fn = getattr(callback.cls, method.lower(), None)
|
||||
|
||||
return coreapi.Link(
|
||||
url=urlparse.urljoin(self.url, path),
|
||||
action=method.lower(),
|
||||
encoding=encoding,
|
||||
description=view_fn.__doc__ if view_fn else '',
|
||||
fields=fields
|
||||
)
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class ExampleView(APIView):
|
|||
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""get documentation"""
|
||||
return Response()
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
@ -171,6 +172,7 @@ class TestSchemaGenerator(TestCase):
|
|||
'read': coreapi.Link(
|
||||
url='/example-view/',
|
||||
action='get',
|
||||
description='get documentation',
|
||||
fields=[]
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user