Project

Profile

Help

Refactor #3552

closed

Swap drf_openapi in favor of drf-yasg

Added by bizhang about 6 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
% Done:

100%

Estimated time:
Platform Release:
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 35
Quarter:

Description

Neither me nor the other maintainer of drf_openapi has had time to put in a lot of time into it, therefore we've agreed to deprecate it in favor of drf-yasg which is more feature complete.
This can be easily swapped in pulp with the following diff:

diff --git a/docs/integration_guide/rest_api/index.rst b/docs/integration_guide/rest_api/index.rst
index db93e8a9e..b5a1edf97 100644
--- a/docs/integration_guide/rest_api/index.rst
+++ b/docs/integration_guide/rest_api/index.rst
@@ -21,4 +21,4 @@ complete version of the API documented below.
     $ pip3 install -e git+https://github.com/limdauto/drf_openapi.git@54d24fb#egg=drf_openapi


-.. swaggerv2doc:: http://localhost:8000/api/v3/docs/?format=openapi
\ No newline at end of file
+.. swaggerv2doc:: http://localhost:8000/api/v3/docs/api.json
\ No newline at end of file
diff --git a/pulpcore/pulpcore/apidocs/__init__.py b/pulpcore/pulpcore/apidocs/__init__.py
deleted file mode 100644
index e69de29bb..000000000
diff --git a/pulpcore/pulpcore/apidocs/views.py b/pulpcore/pulpcore/apidocs/views.py
deleted file mode 100644
index 9f53eb280..000000000
--- a/pulpcore/pulpcore/apidocs/views.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from rest_framework import response, permissions
-from drf_openapi.views import SchemaView
-from drf_openapi.entities import OpenApiSchemaGenerator
-
-
-class DocView(SchemaView):
-    """
-    REST API live documentation endpoint.
-
-    Subclasses drf_openapi.views.SchemaView to provide a publicly accessible
-    REST API documentation endpoint.
-    """
-
-    permission_classes = (permissions.AllowAny,)
-
-    def get(self, request, version):
-        """
-        Override to mark schemas as public.
-
-        :param request:
-        :param version:
-        :return:
-        """
-        generator = OpenApiSchemaGenerator(
-            version=version,
-            url=self.url,
-            title=self.title
-        )
-        return response.Response(generator.get_schema(request, public=True))
diff --git a/pulpcore/pulpcore/app/settings.py b/pulpcore/pulpcore/app/settings.py
index 4259c0559..0986007ad 100644
--- a/pulpcore/pulpcore/app/settings.py
+++ b/pulpcore/pulpcore/app/settings.py
@@ -72,7 +72,7 @@ for entry_point in iter_entry_points('pulpcore.plugin'):
 OPTIONAL_APPS = [
     'crispy_forms',
     'django_extensions',
-    'drf_openapi'
+    'drf_yasg'
 ]

 for app in OPTIONAL_APPS:
diff --git a/pulpcore/pulpcore/app/urls.py b/pulpcore/pulpcore/app/urls.py
index 39ea8f445..3b454dec2 100644
--- a/pulpcore/pulpcore/app/urls.py
+++ b/pulpcore/pulpcore/app/urls.py
@@ -4,6 +4,8 @@ from importlib import import_module

 from django.conf.urls import url, include

+
+from rest_framework import  permissions
 from rest_framework.schemas import get_schema_view
 from rest_framework_nested import routers

@@ -118,14 +120,23 @@ urlpatterns = [

 # if drf_openapi is installed add live docs route
 with suppress(ImportError):
-    import_module('drf_openapi')
-    from pulpcore.apidocs.views import DocView
-    urlpatterns.append(url(r'^api/(?P<version>(v3))/docs/',
-                           DocView.as_view(title='Pulp API Docs'), name='api_schema'))
-
-schema_view = get_schema_view(title='Pulp API')
-
-urlpatterns.append(url(r'^api/v3/$', schema_view))
+    import_module('drf_yasg')
+    from drf_yasg.views import get_schema_view
+    from drf_yasg import openapi
+
+    schema_view = get_schema_view(
+        openapi.Info(
+            title="Pulp3 API",
+            default_version='v3',
+        ),
+        public=True,
+        permission_classes=(permissions.AllowAny,),
+    )
+    urlpatterns = [
+        url(r'^api/v3/docs/api(?P<format>\.json|\.yaml)', schema_view.without_ui(cache_timeout=None), name='schema-json'),
+        url(r'^api/v3/docs/', schema_view.with_ui('redoc', cache_timeout=None), name='schema-redoc'),
+
+    ]

 all_routers = [root_router] + vs_tree.register_with(root_router)
 for router in all_routers:
Actions #1

Updated by bizhang about 6 years ago

  • Tracker changed from Issue to Refactor
  • % Done set to 0
Actions #2

Updated by bizhang about 6 years ago

  • Sprint set to Sprint 35
Actions #3

Updated by dalley about 6 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to dalley
  • Tags Pulp 3 added
Actions #4

Updated by dalley about 6 years ago

  • Status changed from ASSIGNED to POST
Actions #5

Updated by kersom about 6 years ago

Will it be necessary to the user to provide auth to be able access the /api/v3/docs/ ?

Actions #6

Updated by dalley about 6 years ago

I don't know if we have plans to make it restricted eventually, but for now, the code in my PR is:

public=True,
permission_classes=(permissions.AllowAny,),

So the answer is "no" at present.

Added by dalley about 6 years ago

Revision 6feeca12 | View on GitHub

Swap drf_openapi in favor of drf-yasg

closes: #3552 https://pulp.plan.io/issues/3552

Added by dalley about 6 years ago

Revision 6feeca12 | View on GitHub

Swap drf_openapi in favor of drf-yasg

closes: #3552 https://pulp.plan.io/issues/3552

Actions #7

Updated by dalley about 6 years ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100
Actions #8

Updated by daviddavis almost 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #9

Updated by bmbouter almost 5 years ago

  • Tags deleted (Pulp 3)
Actions #10

Updated by bmbouter over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF