@@ -114,6 +114,24 @@ def get_serializer(self, *args, **kwargs):
114
114
assert self .action
115
115
return super (ExampleViewSet , self ).get_serializer (* args , ** kwargs )
116
116
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
+
117
135
118
136
if coreapi :
119
137
schema_view = get_schema_view (title = 'Example API' )
@@ -161,6 +179,13 @@ def test_anonymous_request(self):
161
179
description = 'Custom description.' ,
162
180
)
163
181
},
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
+ },
164
189
'read' : coreapi .Link (
165
190
url = '/example/{id}/' ,
166
191
action = 'get' ,
@@ -263,6 +288,33 @@ def test_authenticated_request(self):
263
288
description = 'Deletion description.' ,
264
289
),
265
290
},
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
+ },
266
318
'update' : coreapi .Link (
267
319
url = '/example/{id}/' ,
268
320
action = 'put' ,
@@ -548,6 +600,13 @@ def test_schema_for_regular_views(self):
548
600
description = 'Custom description.' ,
549
601
)
550
602
},
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
+ },
551
610
'read' : coreapi .Link (
552
611
url = '/example1/{id}/' ,
553
612
action = 'get' ,
0 commit comments