From 4fa4bf025bd94590915d5678c6f1749f403d9655 Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Mon, 5 Feb 2018 18:31:21 +0800 Subject: Add vfc-ztevnfmdriver swagger settings Change-Id: I381c27eeca44e8da78cfee2b9eea0da16a179260 Issue-ID: VFC-736 Signed-off-by: ying.yunlong --- zte/vmanager/driver/settings.py | 43 +++++++++++++++++++++++++++++++------ zte/vmanager/driver/swagger/urls.py | 12 +++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) (limited to 'zte') diff --git a/zte/vmanager/driver/settings.py b/zte/vmanager/driver/settings.py index f5923e22..23750ee7 100644 --- a/zte/vmanager/driver/settings.py +++ b/zte/vmanager/driver/settings.py @@ -43,7 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'driver.pub.database', - 'driver.interfaces' + 'driver.interfaces', + 'drf_yasg', ] MIDDLEWARE_CLASSES = [ @@ -87,6 +88,30 @@ DATABASES = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }} +# 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': 'driver.swagger.urls.swagger_info' +} + TIME_ZONE = 'UTC' # Static files (CSS, JavaScript, Images) @@ -99,22 +124,28 @@ LOGGING = { 'disable_existing_loggers': True, 'formatters': { 'standard': { - 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', }, }, + 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', + }, + }, 'filters': {}, 'handlers': { 'driver_handler': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', - 'filename': os.path.join(BASE_DIR, 'logs/runtime_driver.log'), + 'filename': os.path.join( + BASE_DIR, + 'logs/runtime_driver.log'), 'formatter': 'standard', 'maxBytes': 1024 * 1024 * 50, - 'backupCount': 5, }, }, - + 'backupCount': 5, + }, + }, 'loggers': { 'driver': { 'handlers': ['driver_handler'], 'level': 'DEBUG', - 'propagate': False}, }} + 'propagate': False}, + }} if 'test' in sys.argv: config.REG_TO_MSB_WHEN_START = False diff --git a/zte/vmanager/driver/swagger/urls.py b/zte/vmanager/driver/swagger/urls.py index d2ee8110..39c0febc 100644 --- a/zte/vmanager/driver/swagger/urls.py +++ b/zte/vmanager/driver/swagger/urls.py @@ -13,8 +13,20 @@ # limitations under the License. from django.conf.urls import url +from drf_yasg import openapi + from driver.swagger import views +swagger_info = openapi.Info( + title="vfc-vnfmgr API", + default_version='v1', + description=""" + +The `swagger-ui` view can be found [here](/swagger). +The `ReDoc` view can be found [here](/redoc). +The swagger YAML document can be found [here](/swagger.yaml).""" +) + urlpatterns = [ url(r'^api/ztevnfmdriver/v1/swagger.json$', views.SwaggerView.as_view()), ] -- cgit 1.2.3-korg