Project

Profile

Help

Refactor #3552

Swap drf_openapi in favor of drf-yasg

Added by bizhang over 1 year ago. Updated 7 months ago.

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

100%

Platform Release:
Blocks Release:
Groomed:
No
Sprint Candidate:
No
Tags:
Complexity:
Verified:
No
Verification Required:
No
Sprint:
Sprint 35

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:

Associated revisions

Revision 6feeca12 View on GitHub
Added by dalley over 1 year ago

Swap drf_openapi in favor of drf-yasg

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

Revision 6feeca12 View on GitHub
Added by dalley over 1 year ago

Swap drf_openapi in favor of drf-yasg

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

Revision 6feeca12 View on GitHub
Added by dalley over 1 year ago

Swap drf_openapi in favor of drf-yasg

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

History

#1 Updated by bizhang over 1 year ago

  • Tracker changed from Issue to Refactor
  • % Done set to 0

#2 Updated by bizhang over 1 year ago

  • Sprint set to Sprint 35

#3 Updated by dalley over 1 year ago

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

#4 Updated by dalley over 1 year ago

  • Status changed from ASSIGNED to POST

#5 Updated by kersom over 1 year ago

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

#6 Updated by dalley over 1 year 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.

#7 Updated by dalley over 1 year ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100

#8 Updated by daviddavis 7 months ago

  • Sprint/Milestone set to 3.0

#9 Updated by bmbouter 7 months ago

  • Tags deleted (Pulp 3)

Please register to edit this issue

Also available in: Atom PDF