mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Add schema to ObtainAuthToken
Add encoding parameter to ManualSchema Closes #5676 * Fixed lint errors * Added docs for ManualSchema encoding parameter
This commit is contained in:
parent
878fe895dc
commit
0d5a3a00b0
|
@ -669,6 +669,8 @@ The `ManualSchema` constructor takes two arguments:
|
|||
|
||||
**`description`**: A string description. Optional.
|
||||
|
||||
**`encoding`**: Default `None`. A string encoding, e.g `application/json`. Optional.
|
||||
|
||||
---
|
||||
|
||||
## Core API
|
||||
|
|
|
@ -3,6 +3,9 @@ from rest_framework.authtoken.models import Token
|
|||
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,
|
||||
|
|
|
@ -445,7 +445,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:
|
||||
|
||||
|
@ -455,6 +455,7 @@ class ManualSchema(ViewInspector):
|
|||
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):
|
||||
|
||||
|
@ -464,7 +465,7 @@ class ManualSchema(ViewInspector):
|
|||
return coreapi.Link(
|
||||
url=urlparse.urljoin(base_url, path),
|
||||
action=method.lower(),
|
||||
encoding=None,
|
||||
encoding=self._encoding,
|
||||
fields=self._fields,
|
||||
description=self._description
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user