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
d5178c92
Commit
d5178c92
authored
Aug 05, 2016
by
Tom Christie
Committed by
GitHub
Aug 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include kwargs passed to 'as_view' when generating schemas (#4359)
parent
11a24683
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
0 deletions
+23
-0
rest_framework/schemas.py
+2
-0
rest_framework/viewsets.py
+1
-0
tests/test_schemas.py
+20
-0
No files found.
rest_framework/schemas.py
View file @
d5178c92
...
...
@@ -195,6 +195,8 @@ class SchemaGenerator(object):
Return a `coreapi.Link` instance for the given endpoint.
"""
view
=
callback
.
cls
()
for
attr
,
val
in
getattr
(
callback
,
'initkwargs'
,
{})
.
items
():
setattr
(
view
,
attr
,
val
)
fields
=
self
.
get_path_fields
(
path
,
method
,
callback
,
view
)
fields
+=
self
.
get_serializer_fields
(
path
,
method
,
callback
,
view
)
...
...
rest_framework/viewsets.py
View file @
d5178c92
...
...
@@ -97,6 +97,7 @@ class ViewSetMixin(object):
# generation can pick out these bits of information from a
# resolved URL.
view
.
cls
=
cls
view
.
initkwargs
=
initkwargs
view
.
suffix
=
initkwargs
.
get
(
'suffix'
,
None
)
view
.
actions
=
actions
return
csrf_exempt
(
view
)
...
...
tests/test_schemas.py
View file @
d5178c92
...
...
@@ -5,6 +5,7 @@ from django.test import TestCase, override_settings
from
rest_framework
import
filters
,
pagination
,
permissions
,
serializers
from
rest_framework.compat
import
coreapi
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
rest_framework.routers
import
DefaultRouter
from
rest_framework.schemas
import
SchemaGenerator
...
...
@@ -27,12 +28,21 @@ class ExampleSerializer(serializers.Serializer):
b
=
serializers
.
CharField
(
required
=
False
)
class
AnotherSerializer
(
serializers
.
Serializer
):
c
=
serializers
.
CharField
(
required
=
True
)
d
=
serializers
.
CharField
(
required
=
False
)
class
ExampleViewSet
(
ModelViewSet
):
pagination_class
=
ExamplePagination
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
]
filter_backends
=
[
filters
.
OrderingFilter
]
serializer_class
=
ExampleSerializer
@detail_route
(
methods
=
[
'post'
],
serializer_class
=
AnotherSerializer
)
def
custom_action
(
self
,
request
,
pk
):
return
super
(
ExampleSerializer
,
self
)
.
retrieve
(
self
,
request
)
class
ExampleView
(
APIView
):
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
]
...
...
@@ -120,6 +130,16 @@ class TestRouterGeneratedSchema(TestCase):
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
)
]
),
'custom_action'
:
coreapi
.
Link
(
url
=
'/example/{pk}/custom_action/'
,
action
=
'post'
,
encoding
=
'application/json'
,
fields
=
[
coreapi
.
Field
(
'pk'
,
required
=
True
,
location
=
'path'
),
coreapi
.
Field
(
'c'
,
required
=
True
,
location
=
'form'
),
coreapi
.
Field
(
'd'
,
required
=
False
,
location
=
'form'
),
]
),
'update'
:
coreapi
.
Link
(
url
=
'/example/{pk}/'
,
action
=
'put'
,
...
...
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