mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +03:00
Use the help_text attribute of serializer fields in the schema doc
This commit is contained in:
parent
e407dc7f01
commit
99aa001f10
|
@ -4,6 +4,7 @@ from django.conf import settings
|
|||
from django.contrib.admindocs.views import simplify_regex
|
||||
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.compat import coreapi, uritemplate, urlparse
|
||||
|
@ -258,8 +259,6 @@ class SchemaGenerator(object):
|
|||
if not hasattr(view, 'get_serializer_class'):
|
||||
return []
|
||||
|
||||
fields = []
|
||||
|
||||
serializer_class = view.get_serializer_class()
|
||||
serializer = serializer_class()
|
||||
|
||||
|
@ -269,11 +268,17 @@ class SchemaGenerator(object):
|
|||
if not isinstance(serializer, serializers.Serializer):
|
||||
return []
|
||||
|
||||
fields = []
|
||||
for field in serializer.fields.values():
|
||||
if field.read_only:
|
||||
continue
|
||||
required = field.required and method != 'PATCH'
|
||||
field = coreapi.Field(name=field.source, location='form', required=required)
|
||||
field = coreapi.Field(
|
||||
name=field.source,
|
||||
location='form',
|
||||
required=required,
|
||||
description=force_text(field.help_text),
|
||||
)
|
||||
fields.append(field)
|
||||
|
||||
return fields
|
||||
|
|
|
@ -23,8 +23,8 @@ class ExamplePagination(pagination.PageNumberPagination):
|
|||
|
||||
|
||||
class ExampleSerializer(serializers.Serializer):
|
||||
a = serializers.CharField(required=True)
|
||||
b = serializers.CharField(required=False)
|
||||
a = serializers.CharField(required=True, help_text='About a')
|
||||
b = serializers.CharField(required=False, help_text='About b')
|
||||
|
||||
|
||||
class ExampleViewSet(ModelViewSet):
|
||||
|
@ -109,8 +109,8 @@ class TestRouterGeneratedSchema(TestCase):
|
|||
action='post',
|
||||
encoding='application/json',
|
||||
fields=[
|
||||
coreapi.Field('a', required=True, location='form'),
|
||||
coreapi.Field('b', required=False, location='form')
|
||||
coreapi.Field('a', required=True, location='form', description='About a'),
|
||||
coreapi.Field('b', required=False, location='form', description='About b')
|
||||
]
|
||||
),
|
||||
'retrieve': coreapi.Link(
|
||||
|
@ -126,8 +126,8 @@ class TestRouterGeneratedSchema(TestCase):
|
|||
encoding='application/json',
|
||||
fields=[
|
||||
coreapi.Field('pk', required=True, location='path'),
|
||||
coreapi.Field('a', required=True, location='form'),
|
||||
coreapi.Field('b', required=False, location='form')
|
||||
coreapi.Field('a', required=True, location='form', description='About a'),
|
||||
coreapi.Field('b', required=False, location='form', description='About b')
|
||||
]
|
||||
),
|
||||
'partial_update': coreapi.Link(
|
||||
|
@ -136,8 +136,8 @@ class TestRouterGeneratedSchema(TestCase):
|
|||
encoding='application/json',
|
||||
fields=[
|
||||
coreapi.Field('pk', required=True, location='path'),
|
||||
coreapi.Field('a', required=False, location='form'),
|
||||
coreapi.Field('b', required=False, location='form')
|
||||
coreapi.Field('a', required=False, location='form', description='About a'),
|
||||
coreapi.Field('b', required=False, location='form', description='About b')
|
||||
]
|
||||
),
|
||||
'destroy': coreapi.Link(
|
||||
|
|
Loading…
Reference in New Issue
Block a user