Add vfc-vnfres swagger settings. 85/28985/2
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 24 Jan 2018 06:32:24 +0000 (14:32 +0800)
committeryunlong ying <ying.yunlong@zte.com.cn>
Wed, 24 Jan 2018 07:20:39 +0000 (07:20 +0000)
Change-Id: I2386bea86ba81a3174d5531bda80a0a32bae188c
Issue-ID: VFC-679
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
res/res/settings.py
res/res/urls.py

index 6b19ab5..a6cca4b 100644 (file)
@@ -45,7 +45,8 @@ INSTALLED_APPS = [
     'rest_framework',
     'res.pub.database',
     'res.samples',
-    'res.resources'
+    'res.resources',
+    'drf_yasg',
 ]
 
 MIDDLEWARE_CLASSES = [
@@ -76,6 +77,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': 'res.urls.swagger_info'
+}
+
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
index 9db7895..b9c08ca 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 res.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG_TO_MSB_REG_PARAM
 
+swagger_info = openapi.Info(
+    title="vnfres 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('res.samples.urls')),
     url(r'^', include('res.resources.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