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

✨: Added swagger for API documentation #149

Merged
merged 5 commits into from
Sep 13, 2023
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
15 changes: 15 additions & 0 deletions CMS/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
# Adding djangorestframework to the poject
'rest_framework',
'phonenumber_field',
'drf_spectacular',
'rest_framework_swagger',


#Adding the django filters module
'django_filters',
# for blacklisting used refresh token
Expand Down Expand Up @@ -175,6 +179,9 @@
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),

'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',

'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.UserRateThrottle',
'blog.throttles.BlogRateThrottle',
Expand Down Expand Up @@ -220,6 +227,14 @@
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}

# Spectatular settings
SPECTACULAR_SETTINGS = {
'TITLE': 'Mastori',
'DESCRIPTION': 'Mastori is a community-driven open-source project that aims to provide a simple and efficient blogging platform built with the Django Rest Framework. ',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
}

# CKEDITOR configurations

CKEDITOR_UPLOAD_PATH = '/uploads'
Expand Down
6 changes: 6 additions & 0 deletions CMS/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

admin.site.site_header = "SpaceYaTech CMS Admin"
admin.site.site_title = "SpaceYaTech Admin Portal"
Expand All @@ -17,6 +18,11 @@
path('',include('blog.urls')),

path('ckeditor/', include('ckeditor_uploader.urls')),

# Add the Spectacular views for Swagger documentation
path('schema/', SpectacularAPIView.as_view(), name='schema'),
path('schema/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),

] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ The project is designed to help developers build their own blogging website or a
/account/id/stori/id/reaction/id/
```

## Documentation
```sql
/schema/docs/

```

# Features
Mastori provides the following features:

Expand Down
9 changes: 6 additions & 3 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle

from drf_spectacular.utils import extend_schema,OpenApiParameter
from drf_spectacular.types import OpenApiTypes

from accounts.models import Account
from blog.filters import StoriFilter
from blog.models import Category, Comment, Stori
Expand All @@ -32,7 +35,7 @@ def get_permissions(self):
self.permission_classes = [AllowAny]
return super().get_permissions()


@extend_schema(responses=BlogSerializer)
class StoriViewset(viewsets.ModelViewSet):
""""blog/stori viewset"""
serializer_class = BlogSerializer
Expand All @@ -44,6 +47,7 @@ def perform_create(self, serializer):
#account = Account.objects.get(user=self.request.user)
serializer.save(created_by__user=self.request.user)

@extend_schema(responses=BlogSerializer, parameters=[OpenApiParameter(name="id", type=OpenApiTypes.INT)])
class DraftStoriViewset(viewsets.ModelViewSet):
""""draft Stori viewset"""
serializer_class = BlogSerializer
Expand All @@ -54,8 +58,7 @@ def get_queryset(self):
queryset = Stori.objects.filter(status="Draft", created_by__user=self.request.user)
return queryset



@extend_schema(responses=CommentSerializer, parameters=[ OpenApiParameter(name="mastori_pk", type=OpenApiTypes.INT)])
class CommentViewset(viewsets.ModelViewSet):
"""comment viewset"""
serializer_class = CommentSerializer
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ django-storages==1.13.2
django-templated-email==3.0.1
djangorestframework==3.14.0
djangorestframework-simplejwt==5.2.2
django-rest-swagger==2.2.0
djoser==2.2.0
drf-nested-routers==0.93.4
drf-spectacular==0.26.4
exceptiongroup==1.1.0
gunicorn==20.1.0
iniconfig==2.0.0
Expand Down
Loading