3
3
from rest_framework .authtoken .serializers import AuthTokenSerializer
4
4
from rest_framework .response import Response
5
5
from rest_framework .views import APIView
6
+ from rest_framework .schemas import ManualSchema
7
+ import coreapi
8
+ import coreschema
6
9
7
10
8
11
class ObtainAuthToken (APIView ):
@@ -11,6 +14,29 @@ class ObtainAuthToken(APIView):
11
14
parser_classes = (parsers .FormParser , parsers .MultiPartParser , parsers .JSONParser ,)
12
15
renderer_classes = (renderers .JSONRenderer ,)
13
16
serializer_class = AuthTokenSerializer
17
+ schema = ManualSchema (
18
+ fields = [
19
+ coreapi .Field (
20
+ name = "username" ,
21
+ required = True ,
22
+ location = 'form' ,
23
+ schema = coreschema .String (
24
+ title = "Username" ,
25
+ description = "Valid username for authentication" ,
26
+ ),
27
+ ),
28
+ coreapi .Field (
29
+ name = "password" ,
30
+ required = True ,
31
+ location = 'form' ,
32
+ schema = coreschema .String (
33
+ title = "Password" ,
34
+ description = "Valid password for authentication" ,
35
+ ),
36
+ ),
37
+ ],
38
+ encoding = "application/json" ,
39
+ )
14
40
15
41
def post (self , request , * args , ** kwargs ):
16
42
serializer = self .serializer_class (data = request .data ,
@@ -20,5 +46,4 @@ def post(self, request, *args, **kwargs):
20
46
token , created = Token .objects .get_or_create (user = user )
21
47
return Response ({'token' : token .key })
22
48
23
-
24
49
obtain_auth_token = ObtainAuthToken .as_view ()
0 commit comments