@@ -114,6 +114,24 @@ def get_serializer(self, *args, **kwargs):
114114 assert self .action
115115 return super (ExampleViewSet , self ).get_serializer (* args , ** kwargs )
116116
117+ @action (methods = ['get' , 'post' ], detail = False )
118+ def documented_custom_action (self , request ):
119+ """
120+ get:
121+ A description of the get method on the custom action.
122+
123+ post:
124+ A description of the post method on the custom action.
125+ """
126+ pass
127+
128+ @documented_custom_action .mapping .put
129+ def put_documented_custom_action (self , request , * args , ** kwargs ):
130+ """
131+ A description of the put method on the custom action from mapping.
132+ """
133+ pass
134+
117135
118136if coreapi :
119137 schema_view = get_schema_view (title = 'Example API' )
@@ -161,6 +179,13 @@ def test_anonymous_request(self):
161179 description = 'Custom description.' ,
162180 )
163181 },
182+ 'documented_custom_action' : {
183+ 'read' : coreapi .Link (
184+ url = '/example/documented_custom_action/' ,
185+ action = 'get' ,
186+ description = 'A description of the get method on the custom action.' ,
187+ )
188+ },
164189 'read' : coreapi .Link (
165190 url = '/example/{id}/' ,
166191 action = 'get' ,
@@ -263,6 +288,33 @@ def test_authenticated_request(self):
263288 description = 'Deletion description.' ,
264289 ),
265290 },
291+ 'documented_custom_action' : {
292+ 'read' : coreapi .Link (
293+ url = '/example/documented_custom_action/' ,
294+ action = 'get' ,
295+ description = 'A description of the get method on the custom action.' ,
296+ ),
297+ 'create' : coreapi .Link (
298+ url = '/example/documented_custom_action/' ,
299+ action = 'post' ,
300+ description = 'A description of the post method on the custom action.' ,
301+ encoding = 'application/json' ,
302+ fields = [
303+ coreapi .Field ('a' , required = True , location = 'form' , schema = coreschema .String (title = 'A' , description = 'A field description' )),
304+ coreapi .Field ('b' , required = False , location = 'form' , schema = coreschema .String (title = 'B' ))
305+ ]
306+ ),
307+ 'update' : coreapi .Link (
308+ url = '/example/documented_custom_action/' ,
309+ action = 'put' ,
310+ description = 'A description of the put method on the custom action from mapping.' ,
311+ encoding = 'application/json' ,
312+ fields = [
313+ coreapi .Field ('a' , required = True , location = 'form' , schema = coreschema .String (title = 'A' , description = 'A field description' )),
314+ coreapi .Field ('b' , required = False , location = 'form' , schema = coreschema .String (title = 'B' ))
315+ ]
316+ ),
317+ },
266318 'update' : coreapi .Link (
267319 url = '/example/{id}/' ,
268320 action = 'put' ,
@@ -548,6 +600,13 @@ def test_schema_for_regular_views(self):
548600 description = 'Custom description.' ,
549601 )
550602 },
603+ 'documented_custom_action' : {
604+ 'read' : coreapi .Link (
605+ url = '/example1/documented_custom_action/' ,
606+ action = 'get' ,
607+ description = 'A description of the get method on the custom action.' ,
608+ ),
609+ },
551610 'read' : coreapi .Link (
552611 url = '/example1/{id}/' ,
553612 action = 'get' ,
0 commit comments