Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension for TokenVerifySerializer. #513

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class Fixed(serializers.Serializer):
return auto_schema._map_serializer(Fixed, direction)


class TokenVerifySerializerExtension(OpenApiSerializerExtension):
target_class = 'rest_framework_simplejwt.serializers.TokenVerifySerializer'

def map_serializer(self, auto_schema, direction):
Fixed = inline_serializer('Fixed', fields={
'token': serializers.CharField(write_only=True),
})
return auto_schema._map_serializer(Fixed, direction)


class SimpleJWTScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework_simplejwt.authentication.JWTAuthentication'
name = 'jwtAuth'
Expand Down
1 change: 1 addition & 0 deletions tests/contrib/test_rest_auth_token.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ components:
properties:
token:
type: string
writeOnly: true
required:
- token
UserDetails:
Expand Down
3 changes: 2 additions & 1 deletion tests/contrib/test_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
JWTAuthentication, JWTTokenUserAuthentication,
)
from rest_framework_simplejwt.views import (
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView,
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView,
)
except ImportError:
JWTAuthentication = None
Expand Down Expand Up @@ -44,6 +44,7 @@ def test_simplejwt(no_warnings, view):
path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token-sliding/', TokenObtainSlidingView.as_view(), name='token_obtain_sliding'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('token/verify/', TokenVerifyView.as_view(), name='token_verify'),
]

schema = generate_schema(None, patterns=urlpatterns)
Expand Down
35 changes: 35 additions & 0 deletions tests/contrib/test_simplejwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,33 @@ paths:
schema:
$ref: '#/components/schemas/TokenRefresh'
description: ''
/token/verify/:
post:
operationId: token_verify_create
description: |-
Takes a token and indicates if it is valid. This view provides no
information about a token's fitness for a particular use.
tags:
- token
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TokenVerify'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/TokenVerify'
multipart/form-data:
schema:
$ref: '#/components/schemas/TokenVerify'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/TokenVerify'
description: ''
/x/:
get:
operationId: x_list
Expand Down Expand Up @@ -152,6 +179,14 @@ components:
required:
- access
- refresh
TokenVerify:
type: object
properties:
token:
type: string
writeOnly: true
required:
- token
X:
type: object
properties:
Expand Down