Add swagger of gvnfm-mgr
authorfujinhua <fu.jinhua@zte.com.cn>
Thu, 23 Feb 2017 12:21:05 +0000 (20:21 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Thu, 23 Feb 2017 12:21:05 +0000 (20:21 +0800)
Change-Id: Icb641299a4542f77b4e8941036dfede0938f509c
Issue-Id: GVNFM-41
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
mgr/mgr/swagger/__init__.py [new file with mode: 0644]
mgr/mgr/swagger/swagger.json [new file with mode: 0644]
mgr/mgr/swagger/tests.py [new file with mode: 0644]
mgr/mgr/swagger/urls.py [new file with mode: 0644]
mgr/mgr/swagger/views.py [new file with mode: 0644]
mgr/mgr/urls.py

diff --git a/mgr/mgr/swagger/__init__.py b/mgr/mgr/swagger/__init__.py
new file mode 100644 (file)
index 0000000..c7b6818
--- /dev/null
@@ -0,0 +1,13 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/mgr/mgr/swagger/swagger.json b/mgr/mgr/swagger/swagger.json
new file mode 100644 (file)
index 0000000..c977fbd
--- /dev/null
@@ -0,0 +1,15 @@
+{
+    "swagger": "2.0",
+    "info": {
+        "version": "1.0.0",
+        "title": "VNF Mgr Service rest API"
+    },
+    "basePath": "/openoapi/vnfmgr/v1",
+    "tags": [
+        {
+            "name": "vnfmgr"
+        }
+    ],
+    "paths": {
+    }
+}
\ No newline at end of file
diff --git a/mgr/mgr/swagger/tests.py b/mgr/mgr/swagger/tests.py
new file mode 100644 (file)
index 0000000..adf4a78
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import json
+from django.test import Client
+from rest_framework import status
+
+
+class SwaggerViewTest(unittest.TestCase):
+    def setUp(self):
+        self.client = Client()
+
+    def tearDown(self):
+        pass
+
+    def test_sample(self):
+        response = self.client.get("/openoapi/vnfmgr/v1/swagger.json")
+        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+
diff --git a/mgr/mgr/swagger/urls.py b/mgr/mgr/swagger/urls.py
new file mode 100644 (file)
index 0000000..21f7b8e
--- /dev/null
@@ -0,0 +1,20 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from django.conf.urls import url
+from mgr.swagger import views
+
+urlpatterns = [
+    url(r'^openoapi/vnfmgr/v1/swagger.json$', views.SwaggerView.as_view()), 
+]
diff --git a/mgr/mgr/swagger/views.py b/mgr/mgr/swagger/views.py
new file mode 100644 (file)
index 0000000..e9c9604
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import os
+import json
+from rest_framework.views import APIView
+from rest_framework.response import Response
+
+
+class SwaggerView(APIView):
+    """
+    Show rest api swagger.
+    """
+    def get(self, request, format=None):
+        json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
+        f = open(json_file)
+        json_data = json.JSONDecoder().decode(f.read())
+        f.close()
+        return Response(json_data)
index e086421..564b62e 100644 (file)
@@ -18,6 +18,7 @@ from mgr.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG
 urlpatterns = [
     url(r'^', include('mgr.samples.urls')),
     url(r'^', include('mgr.vnfreg.urls')),
+    url(r'^', include('mgr.swagger.urls')),
 ]
 
 # regist to MSB when startup