Add vfc-vnfmgr auto-swagger settings 61/28761/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Mon, 22 Jan 2018 06:44:34 +0000 (14:44 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Mon, 22 Jan 2018 06:44:34 +0000 (14:44 +0800)
Change-Id: I224a7802c0ae5f404db06ecba715fc2778ae51c1
Issue-ID: VFC-670
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
mgr/mgr/settings.py
mgr/mgr/urls.py
mgr/requirements.txt

index 2a4d223..58cea1f 100644 (file)
@@ -44,7 +44,8 @@ INSTALLED_APPS = [
     'django.contrib.staticfiles',
     'rest_framework',
     'mgr.pub.database',
-    'mgr.samples'
+    'mgr.samples',
+    'drf_yasg',
 ]
 
 MIDDLEWARE_CLASSES = [
@@ -75,6 +76,30 @@ REST_FRAMEWORK = {
     )
 }
 
+# drf-yasg
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+SWAGGER_SETTINGS = {
+    'LOGIN_URL': '/admin/login',
+    'LOGOUT_URL': '/admin/logout',
+
+    'DEFAULT_INFO': 'mgr.urls.swagger_info'
+}
+
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
index 564b62e..84112e2 100644 (file)
 # limitations under the License.
 
 from django.conf.urls import include, url
+from drf_yasg import openapi
+from drf_yasg.views import get_schema_view
+from rest_framework import permissions
+
 from mgr.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG_TO_MSB_REG_PARAM
 
+swagger_info = openapi.Info(
+    title="vnfmgr API",
+    default_version='v1',
+    description="""
+
+The `swagger-ui` view can be found [here](/cached/swagger).
+The `ReDoc` view can be found [here](/cached/redoc).
+The swagger YAML document can be found [here](/cached/swagger.yaml)."""
+)
+
+SchemaView = get_schema_view(
+    validators=['ssv', 'flex'],
+    public=True,
+    permission_classes=(permissions.AllowAny,),
+)
+
 urlpatterns = [
     url(r'^', include('mgr.samples.urls')),
     url(r'^', include('mgr.vnfreg.urls')),
     url(r'^', include('mgr.swagger.urls')),
+    url(r'^swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
+    url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
+    url(r'^redoc/$', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
+    url(r'^cached/swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=None), name='cschema-json'),
+    url(r'^cached/swagger/$', SchemaView.with_ui('swagger', cache_timeout=None), name='cschema-swagger-ui'),
+    url(r'^cached/redoc/$', SchemaView.with_ui('redoc', cache_timeout=None), name='cschema-redoc'),
 ]
 
 # regist to MSB when startup
index c98aff7..3d145d9 100644 (file)
@@ -1,6 +1,6 @@
 # rest framework
-Django==1.9.6
-djangorestframework==3.3.3
+Django==1.11.9
+djangorestframework==3.7.7
 
 # for access MySQL
 MySQL-python==1.2.5
@@ -19,3 +19,16 @@ httplib2==0.9.2
 coverage==4.2
 mock==2.0.0
 unittest_xml_reporting==1.12.0
+
+# for auto swagger
+drf-yasg>=1.2.2
+Pillow>=4.3.0
+pygments>=2.2.0
+django-cors-headers>=2.1.0
+django-filter>=1.1.0,<2.0; python_version == "2.7"
+django-filter>=1.1.0; python_version >= "3.4"
+djangorestframework-camel-case>=0.2.0
+dj-database-url>=0.4.2
+user_agents>=1.1.0
+flex>=6.11.1
+swagger-spec-validator>=2.1.0
\ No newline at end of file