From 9a2f07a128b013ff778744ed1ffdd459f67ad50d Mon Sep 17 00:00:00 2001 From: fujinhua Date: Thu, 23 Feb 2017 20:21:05 +0800 Subject: [PATCH] Add swagger of gvnfm-mgr Change-Id: Icb641299a4542f77b4e8941036dfede0938f509c Issue-Id: GVNFM-41 Signed-off-by: fujinhua --- mgr/mgr/swagger/__init__.py | 13 +++++++++++++ mgr/mgr/swagger/swagger.json | 15 +++++++++++++++ mgr/mgr/swagger/tests.py | 31 +++++++++++++++++++++++++++++++ mgr/mgr/swagger/urls.py | 20 ++++++++++++++++++++ mgr/mgr/swagger/views.py | 29 +++++++++++++++++++++++++++++ mgr/mgr/urls.py | 1 + 6 files changed, 109 insertions(+) create mode 100644 mgr/mgr/swagger/__init__.py create mode 100644 mgr/mgr/swagger/swagger.json create mode 100644 mgr/mgr/swagger/tests.py create mode 100644 mgr/mgr/swagger/urls.py create mode 100644 mgr/mgr/swagger/views.py diff --git a/mgr/mgr/swagger/__init__.py b/mgr/mgr/swagger/__init__.py new file mode 100644 index 0000000..c7b6818 --- /dev/null +++ b/mgr/mgr/swagger/__init__.py @@ -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 index 0000000..c977fbd --- /dev/null +++ b/mgr/mgr/swagger/swagger.json @@ -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 index 0000000..adf4a78 --- /dev/null +++ b/mgr/mgr/swagger/tests.py @@ -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 index 0000000..21f7b8e --- /dev/null +++ b/mgr/mgr/swagger/urls.py @@ -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 index 0000000..e9c9604 --- /dev/null +++ b/mgr/mgr/swagger/views.py @@ -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) diff --git a/mgr/mgr/urls.py b/mgr/mgr/urls.py index e086421..564b62e 100644 --- a/mgr/mgr/urls.py +++ b/mgr/mgr/urls.py @@ -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 -- 2.16.6