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 Swagger Docs #17

Merged
merged 2 commits into from
Feb 4, 2025
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
2 changes: 2 additions & 0 deletions arbisoft_sessions_portal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

# Application definition
Expand All @@ -59,6 +60,7 @@
'django.contrib.staticfiles',
'rest_framework',
'django_filters',
'drf_spectacular',
'users',
'events'
]
Expand Down
5 changes: 5 additions & 0 deletions arbisoft_sessions_portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView


urlpatterns = [
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),

path('admin/', admin.site.urls),
path('api/v1/users/', include('users.v1.urls')),
path('api/v1/events/', include('events.v1.urls')),
Expand Down
19 changes: 19 additions & 0 deletions events/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from drf_spectacular.utils import extend_schema
from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
Expand All @@ -11,6 +12,24 @@

class EventTypeListView(APIView):
""" View for listing the event types """

@extend_schema(
responses={
200: {
"type": "array",
"items": {
"type": "object",
"properties": {
"label": {"type": "string", "example": "SESSION"},
"key": {"type": "string", "example": "session"}
}
},
"example": [
{"label": "SESSION", "key": "session"}
]
}
}
)
def get(self, request, *args, **kwargs):
""" Get the event types """
event_types = [
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ django-cors-headers==4.6.0
django-filter==24.3
djangorestframework==3.15.2
djangorestframework-simplejwt==5.3.1
drf-spectacular==0.28.0
idna==3.10
Markdown==3.7
pillow==11.1.0
Expand Down
64 changes: 63 additions & 1 deletion users/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from drf_spectacular.utils import extend_schema
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.views import APIView
Expand All @@ -17,6 +18,61 @@ class LoginUserView(APIView):

permission_classes = []

@extend_schema(
request=LoginUserSerializer,
responses={
200: {
"type": "object",
"properties": {
"refresh": {
"type": "string",
"description": "JWT refresh token",
"example": "eyJ0eXAiOiJKV1QiLCJhbGc..."
},
"access": {
"type": "string",
"description": "JWT access token",
"example": "eyJ0eXAiOiJKV1QiLCJhbGc..."
},
"user_info": {
"type": "object",
"properties": {
"full_name": {
"type": "string",
"example": "John Doe"
},
"first_name": {
"type": "string",
"example": "John"
},
"last_name": {
"type": "string",
"example": "Doe"
},
"avatar": {
"type": "string",
"format": "uri",
"example": "https://lh3.googleusercontent.com/a/photo"
}
}
}
}
},
400: {
"type": "object",
"properties": {
"detail": {
"type": "string",
"enum": [
"Google Authentication failed",
"Not arbisoft user."
]
}
}
}
},
description="Authenticate user using Google OAuth2 token and return JWT tokens",
)
def post(self, request):
""" Log in the user """

Expand Down Expand Up @@ -58,6 +114,12 @@ def post(self, request):
class HelloWorldView(APIView):
""" View for testing the API """

@extend_schema(
responses={200: {"type": "string", "example": "Hello World"}}
)
def get(self, request):
""" Get the response """
"""
This endpoint returns a simple "Hello World" response.
It can be used to verify that the API is up and running.
"""
return Response("Hello World")