Skip to content

Commit 6cb5a7d

Browse files
Swagger UI
1 parent 9331a1a commit 6cb5a7d

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

Diff for: django_drf_auth_plus/authentication/serializers.py

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ def validate(self, attrs):
1818

1919
def create(self, validated_data):
2020
return User.object.create_user(**validated_data)
21+
22+
23+
class EmailValidationSerializer(serializers.ModelSerializer):
24+
token = serializers.CharField(max_length=555)
25+
26+
class Meta:
27+
model = User
28+
fields = ["token"]

Diff for: django_drf_auth_plus/authentication/views.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from rest_framework.generics import GenericAPIView
22
from rest_framework.response import Response
3-
from rest_framework import status
4-
from .serializers import RegisterSerializer
3+
from rest_framework import status, views
4+
from .serializers import RegisterSerializer, EmailValidationSerializer
55
from rest_framework_simplejwt.tokens import RefreshToken
66
from .models import User
77
from .utils import Util
88
from django.contrib.sites.shortcuts import get_current_site
99
from django.urls import reverse
1010
import jwt
1111
from django.conf import settings
12+
from drf_yasg.utils import swagger_auto_schema
13+
from drf_yasg import openapi
1214

1315

1416
class RegisterView(GenericAPIView):
@@ -34,8 +36,11 @@ def post(self, request):
3436
return Response(user_data, status=status.HTTP_201_CREATED)
3537

3638

37-
class VerifyEmail(GenericAPIView):
39+
class VerifyEmail(views.APIView):
40+
serializer_class = EmailValidationSerializer
41+
token_param_config = openapi.Parameter("token", in_=openapi.IN_QUERY, description="Desc", type=openapi.TYPE_STRING)
3842

43+
@swagger_auto_schema(manual_parameters=[token_param_config])
3944
def get(self, request):
4045
token = request.GET.get("token")
4146

Diff for: django_drf_auth_plus/django_drf_auth_plus/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'django.contrib.staticfiles',
4040
'rest_framework',
4141
'authentication',
42+
'drf_yasg',
4243
]
4344

4445
REST_FRAMEWORK = {

Diff for: django_drf_auth_plus/django_drf_auth_plus/urls.py

+19
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,27 @@
1616
from django.contrib import admin
1717
from django.urls import path, include
1818
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
19+
from rest_framework import permissions
20+
from drf_yasg.views import get_schema_view
21+
from drf_yasg import openapi
22+
23+
24+
schema_view = get_schema_view(
25+
openapi.Info(
26+
title="Authentication API",
27+
default_version='v1',
28+
description="Test description",
29+
terms_of_service="https://www.google.com/policies/terms/",
30+
contact=openapi.Contact(email="[email protected]"),
31+
license=openapi.License(name="BSD License"),
32+
),
33+
public=True,
34+
permission_classes=(permissions.AllowAny,),
35+
)
1936

2037
urlpatterns = [
38+
path('', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
39+
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
2140
path('admin/', admin.site.urls),
2241
path("auth/", include("authentication.urls")),
2342
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),

Diff for: requirements.txt

+18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
asgiref==3.3.4
2+
certifi==2020.12.5
3+
chardet==4.0.0
4+
coreapi==2.3.3
5+
coreschema==0.0.4
26
Django==3.2
37
djangorestframework==3.12.4
48
djangorestframework-simplejwt==4.6.0
9+
drf-yasg==1.20.0
10+
future==0.18.2
11+
idna==2.10
12+
inflection==0.5.1
13+
itypes==1.2.0
14+
Jinja2==2.11.3
15+
MarkupSafe==1.1.1
16+
packaging==20.9
517
PyJWT==1.7.1
18+
pyparsing==2.4.7
619
pytz==2021.1
20+
requests==2.25.1
21+
ruamel.yaml==0.17.4
22+
ruamel.yaml.clib==0.2.2
723
sqlparse==0.4.1
24+
uritemplate==3.0.1
25+
urllib3==1.26.4

0 commit comments

Comments
 (0)