summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-24 14:32:24 +0800
committeryunlong ying <ying.yunlong@zte.com.cn>2018-01-24 07:20:39 +0000
commite490302b5b7f47588a83deaa26c623013b88aaa0 (patch)
treedfcadb8a52d14c95a2be75b235ba57e1d15ccf57 /res
parentbdb62a796f2d71051984a6e2036f1a0b7ce5484b (diff)
Add vfc-vnfres swagger settings.
Change-Id: I2386bea86ba81a3174d5531bda80a0a32bae188c Issue-ID: VFC-679 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'res')
-rw-r--r--res/res/settings.py27
-rw-r--r--res/res/urls.py26
2 files changed, 52 insertions, 1 deletions
diff --git a/res/res/settings.py b/res/res/settings.py
index 6b19ab5..a6cca4b 100644
--- a/res/res/settings.py
+++ b/res/res/settings.py
@@ -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',
diff --git a/res/res/urls.py b/res/res/urls.py
index 9db7895..b9c08ca 100644
--- a/res/res/urls.py
+++ b/res/res/urls.py
@@ -13,11 +13,37 @@
# 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