From ef3375355cb5c3b8f96546eea1591b1d69047483 Mon Sep 17 00:00:00 2001 From: Paulo Scardine Date: Sun, 17 Dec 2017 02:11:15 -0200 Subject: [PATCH] Add schema to ObtainAuthToken Add encoding parameter to ManualSchema --- rest_framework/authtoken/views.py | 27 ++++++++++++++++++++++++++- rest_framework/schemas/inspectors.py | 5 +++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/rest_framework/authtoken/views.py b/rest_framework/authtoken/views.py index 6254d2f7f9..e218561947 100644 --- a/rest_framework/authtoken/views.py +++ b/rest_framework/authtoken/views.py @@ -3,6 +3,9 @@ from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework.schemas import ManualSchema +import coreapi +import coreschema class ObtainAuthToken(APIView): @@ -11,6 +14,29 @@ class ObtainAuthToken(APIView): parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,) renderer_classes = (renderers.JSONRenderer,) serializer_class = AuthTokenSerializer + schema = ManualSchema( + fields=[ + coreapi.Field( + name="username", + required=True, + location='form', + schema=coreschema.String( + title="Username", + description="Valid username for authentication", + ), + ), + coreapi.Field( + name="password", + required=True, + location='form', + schema=coreschema.String( + title="Password", + description="Valid password for authentication", + ), + ), + ], + encoding="application/json", + ) def post(self, request, *args, **kwargs): serializer = self.serializer_class(data=request.data, @@ -20,5 +46,4 @@ def post(self, request, *args, **kwargs): token, created = Token.objects.get_or_create(user=user) return Response({'token': token.key}) - obtain_auth_token = ObtainAuthToken.as_view() diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index b2a5320bd2..ea0304475a 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -432,7 +432,7 @@ class ManualSchema(ViewInspector): Allows providing a list of coreapi.Fields, plus an optional description. """ - def __init__(self, fields, description=''): + def __init__(self, fields, description='', encoding=None): """ Parameters: @@ -442,6 +442,7 @@ def __init__(self, fields, description=''): assert all(isinstance(f, coreapi.Field) for f in fields), "`fields` must be a list of coreapi.Field instances" self._fields = fields self._description = description + self._encoding = encoding def get_link(self, path, method, base_url): @@ -451,7 +452,7 @@ def get_link(self, path, method, base_url): return coreapi.Link( url=urlparse.urljoin(base_url, path), action=method.lower(), - encoding=None, + encoding=self._encoding, fields=self._fields, description=self._description ) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy