From: ying.yunlong Date: Mon, 22 Jan 2018 06:44:34 +0000 (+0800) Subject: Add vfc-vnfmgr auto-swagger settings X-Git-Tag: v1.1.0~39 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=36e8652d05c309e6ae6f6c8b7609fdfa8614f3ab;p=vfc%2Fgvnfm%2Fvnfmgr.git Add vfc-vnfmgr auto-swagger settings Change-Id: I224a7802c0ae5f404db06ecba715fc2778ae51c1 Issue-ID: VFC-670 Signed-off-by: ying.yunlong --- diff --git a/mgr/mgr/settings.py b/mgr/mgr/settings.py index 2a4d223..58cea1f 100644 --- a/mgr/mgr/settings.py +++ b/mgr/mgr/settings.py @@ -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', diff --git a/mgr/mgr/urls.py b/mgr/mgr/urls.py index 564b62e..84112e2 100644 --- a/mgr/mgr/urls.py +++ b/mgr/mgr/urls.py @@ -13,12 +13,38 @@ # 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.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.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 diff --git a/mgr/requirements.txt b/mgr/requirements.txt index c98aff7..3d145d9 100644 --- a/mgr/requirements.txt +++ b/mgr/requirements.txt @@ -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