prije uspostave API documentation

This commit is contained in:
emaric 2024-01-16 08:49:37 +01:00
parent ade8ea32e2
commit 92d98a299c
6 changed files with 48 additions and 1 deletions

View File

@ -19,6 +19,8 @@ class ObjektSigurnostiList(generics.ListCreateAPIView):
queryset = ObjektSigurnosti.objects.all().order_by("naziv")
serializer_class = ObjektSigurnostiSerializer
pagination_class = CustomObjektSigurnostiPagination
permission_classes = []
def get_queryset(self):
user = self.request.user

View File

@ -49,6 +49,8 @@ INSTALLED_APPS = [
'django_extensions',
# 3rd party
'rest_framework',
'drf_yasg',
'rest_framework_swagger',
# Custom apps:
'plovidba_aplikacija',
@ -122,6 +124,21 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Define DRF settings
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework_simplejwt.authentication.JWTAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
"PAGE_SIZE": 100,
}
# API docs
SHOW_API_DOCS = ENV_BOOL("SHOW_API_DOCS", True)
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

View File

@ -14,11 +14,39 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from plovidba_aplikacija import views
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework import permissions
api_schema_view = get_schema_view(
openapi.Info(
title="API docs",
default_version='v1',
description="Swagger docs for ListLabs API",
contact=openapi.Contact(email="elena.maric@listlabs.net")
),
public=True,
permission_classes=[permissions.AllowAny],
)
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('plovidba_aplikacija.urls')),
]
path("swagger/", api_schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path("redoc/", api_schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
]
if settings.SHOW_API_DOCS:
urlpatterns += [
path('api/docs/swagger/',
api_schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('api/docs/redoc/',
api_schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc-ui')
]