Evgeny Polivanov před 1 rokem
rodič
revize
836135a5c6

+ 23 - 1
SharixAdmin/apiviews.py

@@ -7,6 +7,22 @@ from SharixAdmin.models import *
 from rest_framework.views import APIView
 from rest_framework.response import Response
 from xmpp import cli
+from drf_yasg.views import get_schema_view
+from drf_yasg import openapi
+from drf_yasg.utils import swagger_auto_schema
+
+schema_view = get_schema_view(
+   openapi.Info(
+      title="ShariX Admin Open API",
+      default_version='v1',
+      description="REST API Documentation",
+      #terms_of_service="https://www.google.com/policies/terms/",
+      #contact=openapi.Contact(email="contact@snippets.local"),
+      #license=openapi.License(name="BSD License"),
+   ),
+   public=False,
+   permission_classes=[permissions.IsAuthenticated],
+)
 
 class SharixUserMVS(viewsets.ModelViewSet):
     queryset = SharixUser.objects.all()
@@ -33,11 +49,17 @@ class GroupMVS(viewsets.ModelViewSet):
 
     
 class PhoneSender(APIView):
+    """
+    Test description one
+    """
+    
     permission_classes = [permissions.IsAdminUser, permissions.IsAuthenticated]
-
+    
+    @swagger_auto_schema(operation_description="Test description two")
     def get(self, request, format=None):
         return Response({"message": "Для отправки сообщения используйте POST-запрос"})
     
+    @swagger_auto_schema(operation_description="Test description three")
     def post(self, request, format=None):
         cli.send_message("sender", "password", "getter", request.data)
         return Response({"message": "Сообщение успешно отправлено!"})

+ 73 - 0
SharixAdmin/static/drf-yasg/style.css

@@ -0,0 +1,73 @@
+html {
+    box-sizing: border-box;
+    overflow: -moz-scrollbars-vertical;
+    overflow-y: scroll;
+}
+
+*,
+*:before,
+*:after {
+    box-sizing: inherit;
+}
+
+body {
+    margin: 0;
+    padding: 0;
+}
+
+body.swagger-body {
+    background: #fafafa;
+}
+
+.hidden {
+    display: none;
+}
+
+#django-session-auth > div {
+    display: inline-block;
+}
+
+#django-session-auth .btn.authorize {
+    padding: 10px 23px;
+}
+
+#django-session-auth .btn.authorize a {
+    color: #49cc90;
+    text-decoration: none;
+}
+
+#django-session-auth .hello {
+    margin-right: 5px;
+}
+
+#django-session-auth .hello .django-session {
+    font-weight: bold;
+}
+
+.label {
+    display: inline;
+    padding: .2em .6em .3em;
+    font-weight: 700;
+    line-height: 1;
+    color: #fff;
+    text-align: center;
+    white-space: nowrap;
+    vertical-align: baseline;
+    border-radius: .25em;
+}
+
+.label-primary {
+    background-color: #337ab7;
+}
+
+.divider {
+    margin-right: 8px;
+    background: #16222c44;
+    width: 2px;
+}
+
+svg.swagger-defs {
+    position: absolute;
+    width: 0;
+    height: 0;
+}

+ 2 - 3
SharixAdmin/templates/SharixAdmin/main.html

@@ -12,9 +12,8 @@
                     <li class="list-group-item"><a  href="https://wiki.sharix-app.org/doku.php/sharix/legal/pravila_okazanija_uslug">Правила оказания услуг</a></li>
                     <li class="list-group-item"><a  href="https://wiki.sharix-app.org/doku.php/sharix/legal/porjadok_okazanija_uslug">Порядок оказания услуг</a></li>
                     <li class="list-group-item"><a  href="https://wiki.sharix-app.org/doku.php/sharix/legal/perechen_uslug_platformy">Перечень услуг</a></li>
-                    <li class="list-group-item"><a  href="{% url 'schemav1' %}">Схема 1</a></li>
-                    <li class="list-group-item"><a  href="{% url 'schemav2' %}">Схема 2</a></li>
-                    <li class="list-group-item"><a  href="{% url 'schema' %}">Схема 3</a></li>
+                    <li class="list-group-item"><a  href="{% url 'schemav1' %}">Схема 1</a> / <a  href="{% url 'schemav2' %}">Схема 2</a> / <a  href="{% url 'schema' %}">Схема 3</a> / <a  href="{% url 'schema-redoc' %}">API Docs</a></li>
+                
                   </ul>
             </div>
             <div class="col-6 text-end">

+ 48 - 0
SharixAdmin/templates/drf-yasg/redoc.html

@@ -0,0 +1,48 @@
+{% load static %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8"/>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>{% block title %}{{ title }}{% endblock %}</title>
+
+    {% block extra_head %}
+        {# -- Add any extra HTML heads tags here - except scripts and styles -- #}
+    {% endblock %}
+
+    {% block favicon %}
+        {# -- Maybe replace the favicon -- #}
+        <link rel="icon" type="image/png" href="{% static 'SharixAdmin/img/logo.svg' %}"/>
+    {% endblock %}
+
+    {% block main_styles %}
+        <link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
+    {% endblock %}
+    {% block extra_styles %}
+        {# -- Add any additional CSS scripts here -- #}
+    {% endblock %}
+</head>
+<body>
+
+{% block extra_body %}
+    {# -- Add any header/body markup here (rendered BEFORE the swagger-ui/redoc element) -- #}
+{% endblock %}
+
+<div id="redoc-placeholder"></div>
+
+{% block footer %}
+    {# -- Add any footer markup here (rendered AFTER the swagger-ui/redoc element) -- #}
+{% endblock %}
+
+<script id="redoc-settings" type="application/json">{{ redoc_settings | safe }}</script>
+
+{% block main_scripts %}
+    <script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
+    <script src="{% static 'drf-yasg/redoc-init.js' %}"></script>
+    <script src="{% static 'drf-yasg/redoc/redoc.min.js' %}"></script>
+{% endblock %}
+{% block extra_scripts %}
+    {# -- Add any additional scripts here -- #}
+{% endblock %}
+</body>
+</html>

+ 3 - 1
SharixAdmin/urls.py

@@ -21,10 +21,12 @@ urlpatterns = [
     
     #path('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),
-    path('api/', include(router.urls)),
+    path('platform/api/', include(router.urls), name="sharix-api"),
     path('senderphone/', PhoneSender.as_view()),
     #schemas
     path('schemav1/', login_required(Schema.as_view()), name='schemav1'),
     path('schemav2/', login_required(Plate.as_view()),  name='schemav2'),
     path('schemav3/', schema_v3, name='schema'),
+
+    re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
 ]

+ 1 - 0
core/settings.py

@@ -34,6 +34,7 @@ INSTALLED_APPS = [
     'rest_framework.authtoken',
     'djoser',
     'schema_graph',
+    'drf_yasg',
     'django_spaghetti',
 ]