Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
116917db
Commit
116917db
authored
Aug 11, 2016
by
Tom Christie
Committed by
GitHub
Aug 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add form field descriptions to schemas (#4387)
parent
01b498ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
rest_framework/schemas.py
+8
-1
tests/test_schemas.py
+4
-4
No files found.
rest_framework/schemas.py
View file @
116917db
...
@@ -4,6 +4,7 @@ from django.conf import settings
...
@@ -4,6 +4,7 @@ from django.conf import settings
from
django.contrib.admindocs.views
import
simplify_regex
from
django.contrib.admindocs.views
import
simplify_regex
from
django.core.urlresolvers
import
RegexURLPattern
,
RegexURLResolver
from
django.core.urlresolvers
import
RegexURLPattern
,
RegexURLResolver
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.encoding
import
force_text
from
rest_framework
import
exceptions
,
serializers
from
rest_framework
import
exceptions
,
serializers
from
rest_framework.compat
import
coreapi
,
uritemplate
,
urlparse
from
rest_framework.compat
import
coreapi
,
uritemplate
,
urlparse
...
@@ -295,7 +296,13 @@ class SchemaGenerator(object):
...
@@ -295,7 +296,13 @@ class SchemaGenerator(object):
if
field
.
read_only
:
if
field
.
read_only
:
continue
continue
required
=
field
.
required
and
method
!=
'PATCH'
required
=
field
.
required
and
method
!=
'PATCH'
field
=
coreapi
.
Field
(
name
=
field
.
source
,
location
=
'form'
,
required
=
required
)
description
=
force_text
(
field
.
help_text
)
if
field
.
help_text
else
''
field
=
coreapi
.
Field
(
name
=
field
.
source
,
location
=
'form'
,
required
=
required
,
description
=
description
)
fields
.
append
(
field
)
fields
.
append
(
field
)
return
fields
return
fields
...
...
tests/test_schemas.py
View file @
116917db
...
@@ -24,7 +24,7 @@ class ExamplePagination(pagination.PageNumberPagination):
...
@@ -24,7 +24,7 @@ class ExamplePagination(pagination.PageNumberPagination):
class
ExampleSerializer
(
serializers
.
Serializer
):
class
ExampleSerializer
(
serializers
.
Serializer
):
a
=
serializers
.
CharField
(
required
=
True
)
a
=
serializers
.
CharField
(
required
=
True
,
help_text
=
'A field description'
)
b
=
serializers
.
CharField
(
required
=
False
)
b
=
serializers
.
CharField
(
required
=
False
)
...
@@ -131,7 +131,7 @@ class TestRouterGeneratedSchema(TestCase):
...
@@ -131,7 +131,7 @@ class TestRouterGeneratedSchema(TestCase):
action
=
'post'
,
action
=
'post'
,
encoding
=
'application/json'
,
encoding
=
'application/json'
,
fields
=
[
fields
=
[
coreapi
.
Field
(
'a'
,
required
=
True
,
location
=
'form'
),
coreapi
.
Field
(
'a'
,
required
=
True
,
location
=
'form'
,
description
=
'A field description'
),
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
]
]
),
),
...
@@ -162,7 +162,7 @@ class TestRouterGeneratedSchema(TestCase):
...
@@ -162,7 +162,7 @@ class TestRouterGeneratedSchema(TestCase):
encoding
=
'application/json'
,
encoding
=
'application/json'
,
fields
=
[
fields
=
[
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
),
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
),
coreapi
.
Field
(
'a'
,
required
=
True
,
location
=
'form'
),
coreapi
.
Field
(
'a'
,
required
=
True
,
location
=
'form'
,
description
=
'A field description'
),
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
]
]
),
),
...
@@ -172,7 +172,7 @@ class TestRouterGeneratedSchema(TestCase):
...
@@ -172,7 +172,7 @@ class TestRouterGeneratedSchema(TestCase):
encoding
=
'application/json'
,
encoding
=
'application/json'
,
fields
=
[
fields
=
[
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
),
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
),
coreapi
.
Field
(
'a'
,
required
=
False
,
location
=
'form'
),
coreapi
.
Field
(
'a'
,
required
=
False
,
location
=
'form'
,
description
=
'A field description'
),
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
coreapi
.
Field
(
'b'
,
required
=
False
,
location
=
'form'
)
]
]
),
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment