swagger supports for catalog1 17/8617/2
authormaopengzhang <zhang.maopeng1@zte.com.cn>
Thu, 24 Aug 2017 11:46:56 +0000 (19:46 +0800)
committeryunlong ying <ying.yunlong@zte.com.cn>
Thu, 24 Aug 2017 12:12:11 +0000 (12:12 +0000)
Support swagger file in catalog

Change-Id: Ieb2778fd4239cdae66d660f536f930e5d0011db1
Issue-ID: VFC-145
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
catalog/settings.py
catalog/swagger/__init__.py [new file with mode: 0644]
catalog/swagger/tests.py [new file with mode: 0644]
catalog/swagger/urls.py [new file with mode: 0644]
catalog/swagger/vfc.catalog.swagger.json [new file with mode: 0644]
catalog/swagger/views.py [new file with mode: 0644]
catalog/urls.py

index 629f68a..3c13ade 100644 (file)
@@ -45,7 +45,8 @@ INSTALLED_APPS = [
     'django.contrib.staticfiles',
     'rest_framework',
     'catalog.pub.database',
-    'catalog.samples'
+    'catalog.samples',
+    'catalog.swagger'
 ]
 
 MIDDLEWARE_CLASSES = [
diff --git a/catalog/swagger/__init__.py b/catalog/swagger/__init__.py
new file mode 100644 (file)
index 0000000..49c7b94
--- /dev/null
@@ -0,0 +1,10 @@
+# Copyright 2016-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.
diff --git a/catalog/swagger/tests.py b/catalog/swagger/tests.py
new file mode 100644 (file)
index 0000000..40aaea7
--- /dev/null
@@ -0,0 +1,30 @@
+# Copyright 2016-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.
+
+import unittest
+import json
+from django.test import Client
+from rest_framework import status
+
+
+class SampleViewTest(unittest.TestCase):
+    def setUp(self):
+        self.client = Client()
+
+    def tearDown(self):
+        pass
+
+    def test_sample(self):
+        response = self.client.get("/api/catalog/v1/swagger.json")
+        print response
+        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+#        resp_data = json.loads(response.content)
+#        self.assertEqual({"status": "active"}, resp_data)
diff --git a/catalog/swagger/urls.py b/catalog/swagger/urls.py
new file mode 100644 (file)
index 0000000..b807b88
--- /dev/null
@@ -0,0 +1,23 @@
+# Copyright 2016-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 patterns, url
+from rest_framework.urlpatterns import format_suffix_patterns
+
+from catalog.swagger.views import SwaggerJsonView
+
+urlpatterns = patterns('',
+                       url(r'^api/catalog/v1/swagger.json$', SwaggerJsonView.as_view())
+                       )
+
+urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/catalog/swagger/vfc.catalog.swagger.json b/catalog/swagger/vfc.catalog.swagger.json
new file mode 100644 (file)
index 0000000..ece4cd4
--- /dev/null
@@ -0,0 +1,510 @@
+{\r
+  "swagger": "2.0",\r
+  "info": {\r
+    "version": "1.0.0",\r
+    "title": "ONAP VFC Catalog Rest API",\r
+    "description": "VFC Catalog Management API.",\r
+    "contact": {\r
+      "name": "ONAP VFC team",\r
+      "email": "onap-discuss@lists.onap.org",\r
+      "url": "https://gerrit.onap.org/r/#/admin/projects/vfc/nfvo/catalog"\r
+    }\r
+  },\r
+  "basePath": "/api/catalog/v1",\r
+  "schemes": [\r
+    "http",\r
+    "https"\r
+  ],\r
+  "consumes": [\r
+    "application/json"\r
+  ],\r
+  "produces": [\r
+    "application/json"\r
+  ],\r
+  "paths": {\r
+    "/nspackages": {\r
+      "get": {\r
+        "tags": [\r
+          "nspackage"\r
+        ],\r
+        "summary": "query ns packages info",\r
+        "description": "query ns packages info",\r
+        "operationId": "query_ns_packages",\r
+        "parameters": [],\r
+        "responses": {\r
+          "200": {\r
+            "description": "successful operation",\r
+            "schema": {\r
+              "$ref": "#/definitions/NsPkgListInfo"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      },\r
+      "post": {\r
+        "tags": [\r
+          "nspackage"\r
+        ],\r
+        "summary": "ns package distribute",\r
+        "description": "ns package distribute",\r
+        "operationId": "ns_pkg_distribute",\r
+        "parameters": [\r
+          {\r
+            "in": "body",\r
+            "name": "body",\r
+            "description": "distribute request param",\r
+            "required": true,\r
+            "schema": {\r
+              "$ref": "#/definitions/NsPkgDistributeRequest"\r
+            }\r
+          }\r
+        ],\r
+        "responses": {\r
+          "202": {\r
+            "description": "",\r
+            "schema": {\r
+              "$ref": "#/definitions/NsPkgDistributeResponse"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      }\r
+    },\r
+    "/nspackages/{csarId}": {\r
+      "get": {\r
+        "tags": [\r
+          "nspackage"\r
+        ],\r
+        "summary": "query ns package info",\r
+        "description": "query ns package info via ns package csarId",\r
+        "operationId": "query_ns_package",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [\r
+          {\r
+            "name": "csarId",\r
+            "in": "path",\r
+            "description": "csar id of ns package",\r
+            "required": true,\r
+            "type": "string"\r
+          }\r
+        ],\r
+        "responses": {\r
+          "200": {\r
+            "description": "successful operation",\r
+            "schema": {\r
+              "$ref": "#/definitions/NsPkgDetailInfo"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      },\r
+      "delete": {\r
+        "tags": [\r
+          "nspackage"\r
+        ],\r
+        "summary": "delete ns pkg",\r
+        "description": "delete ns pkg",\r
+        "operationId": "delete_ns_pkg",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [\r
+          {\r
+            "name": "csarId",\r
+            "in": "path",\r
+            "description": "csar id of ns package",\r
+            "required": true,\r
+            "type": "string"\r
+          }\r
+        ],\r
+        "responses": {\r
+          "202": {\r
+            "description": "",\r
+            "schema": {\r
+              "$ref": "#/definitions/NsPkgDelResponse"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      }\r
+    },\r
+    "/vnfpackages": {\r
+      "get": {\r
+        "tags": [\r
+          "vnfpackage"\r
+        ],\r
+        "summary": "query vnf packages info",\r
+        "description": "query vnf packages info",\r
+        "operationId": "query_vnf_packages",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [],\r
+        "responses": {\r
+          "200": {\r
+            "description": "successful operation",\r
+            "schema": {\r
+              "$ref": "#/definitions/VnfPkgListInfo"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      },\r
+      "post": {\r
+        "tags": [\r
+          "vnfpackage"\r
+        ],\r
+        "summary": "vnf package distribute",\r
+        "description": "vnf package distribute",\r
+        "operationId": "vnf_pkg_distribute",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [\r
+          {\r
+            "in": "body",\r
+            "name": "body",\r
+            "description": "distribute request param",\r
+            "required": true,\r
+            "schema": {\r
+              "$ref": "#/definitions/VnfPkgDistributeRequest"\r
+            }\r
+          }\r
+        ],\r
+        "responses": {\r
+          "202": {\r
+            "description": "",\r
+            "schema": {\r
+              "$ref": "#/definitions/VnfPkgDistributeResponse"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      }\r
+    },\r
+    "/vnfpackages/{csarId}": {\r
+      "get": {\r
+        "tags": [\r
+          "vnfpackage"\r
+        ],\r
+        "summary": "query vnf package info",\r
+        "description": "query one vnf package info via vnf package csarId",\r
+        "operationId": "query_vnf_package",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [\r
+          {\r
+            "name": "csarId",\r
+            "in": "path",\r
+            "description": "csar id of vnf package",\r
+            "required": true,\r
+            "type": "string"\r
+          }\r
+        ],\r
+        "responses": {\r
+          "200": {\r
+            "description": "successful operation",\r
+            "schema": {\r
+              "$ref": "#/definitions/VnfPkgDetailInfo"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      },\r
+      "delete": {\r
+        "tags": [\r
+          "vnfpackage"\r
+        ],\r
+        "summary": "delete vnf package",\r
+        "description": "delete vnf package",\r
+        "operationId": "delete_vnf_package",\r
+        "consumes": [\r
+          "application/json"\r
+        ],\r
+        "produces": [\r
+          "application/json"\r
+        ],\r
+        "parameters": [\r
+          {\r
+            "name": "csarId",\r
+            "in": "path",\r
+            "description": "csar id of vnf package",\r
+            "required": true,\r
+            "type": "string"\r
+          }\r
+        ],\r
+        "responses": {\r
+          "202": {\r
+            "description": "",\r
+            "schema": {\r
+              "$ref": "#/definitions/VnfPkgDelResponse"\r
+            }\r
+          },\r
+          "500": {\r
+            "description": "internal error"\r
+          }\r
+        }\r
+      }\r
+    }\r
+  },\r
+  "definitions": {\r
+    "NsPkgDistributeRequest": {\r
+      "type": "object",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string",\r
+          "description": "network service package id, UUID"\r
+        }\r
+      }\r
+    },\r
+    "NsPkgDistributeResponse": {\r
+      "type": "object",\r
+      "properties": {\r
+        "status": {\r
+          "type": "string",\r
+          "description": "Operation status. value is success or failed"\r
+        },\r
+        "statusDescription": {\r
+          "type": "string",\r
+          "description": "description about the operation result"\r
+        },\r
+        "errorCode": {\r
+          "type": "string",\r
+          "description": "If the status is failed, the errorcode will be returned"\r
+        }\r
+      }\r
+    },\r
+    "NsPkgDelResponse": {\r
+      "type": "object",\r
+      "properties": {\r
+        "status": {\r
+          "type": "string",\r
+          "description": "Operation status. value is success or failed"\r
+        },\r
+        "statusDescription": {\r
+          "type": "string",\r
+          "description": "description about the operation result"\r
+        },\r
+        "errorCode": {\r
+          "type": "string",\r
+          "description": "If the status is failed, the errorcode will be returned"\r
+        }\r
+      }\r
+    },\r
+    "NsPkgListInfo": {\r
+      "type": "array",\r
+      "items": {\r
+        "$ref": "#/definitions/NsPkgInfo"\r
+      }\r
+    },\r
+    "NsPkgDetailInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string"\r
+        },\r
+        "NsPackageInfo": {\r
+          "$ref": "#/definitions/NsPkgInfo"\r
+        },\r
+        "NsInstanceInfo": {\r
+          "$ref": "#/definitions/NsInstListInfo"\r
+        }\r
+      }\r
+    },\r
+    "NsPkgInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string",\r
+          "description": "network service package id, UUID"\r
+        },\r
+        "nsdId": {\r
+          "type": "string",\r
+          "description": "network service descriptor ID"\r
+        },\r
+        "nsdProvider": {\r
+          "type": "string",\r
+          "description": "network service designer name"\r
+        },\r
+        "nsdVersion": {\r
+          "type": "string",\r
+          "description": "network service descriptor version"\r
+        }\r
+      }\r
+    },\r
+    "NsInstListInfo": {\r
+      "type": "array",\r
+      "items": {\r
+        "$ref": "#/definitions/NsInstInfo"\r
+      }\r
+    },\r
+    "NsInstInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "nsInstanceId": {\r
+          "type": "string",\r
+          "description": "network service instance ID"\r
+        },\r
+        "nsInstanceName": {\r
+          "type": "string",\r
+          "description": "network service instance name"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgDistributeRequest": {\r
+      "type": "object",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string",\r
+          "description": "vnf package id, UUID"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgDistributeResponse": {\r
+      "type": "object",\r
+      "properties": {\r
+        "jobId": {\r
+          "type": "string",\r
+          "description": "VNF package distribute job ID"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgDelResponse": {\r
+      "type": "object",\r
+      "properties": {\r
+        "status": {\r
+          "type": "string",\r
+          "description": "Operation status. value is success or failed"\r
+        },\r
+        "statusDescription": {\r
+          "type": "string",\r
+          "description": "description about the operation result"\r
+        },\r
+        "errorCode": {\r
+          "type": "string",\r
+          "description": "If the status is failed, the errorcode will be returned"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgListInfo": {\r
+      "type": "array",\r
+      "items": {\r
+        "$ref": "#/definitions/VnfPkgInfo"\r
+      }\r
+    },\r
+    "VnfPkgDetailInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string",\r
+          "description": "vnf package id, UUID"\r
+        },\r
+        "packageInfo": {\r
+          "$ref": "#/definitions/VnfPkgInfo"\r
+        },\r
+        "imageInfo": {\r
+          "$ref": "#/definitions/VnfPkgImgListInfo"\r
+        },\r
+        "vnfInstanceInfo": {\r
+          "$ref": "#/definitions/VnfInstListInfo"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgInfo": {\r
+      "type": "object",\r
+      "description": "vnf package infomation",\r
+      "properties": {\r
+        "csarId": {\r
+          "type": "string",\r
+          "description": "vnf package id, UUID"\r
+        },\r
+        "vnfdId": {\r
+          "type": "string",\r
+          "description": "VNF descriptor ID"\r
+        },\r
+        "vnfdProvider": {\r
+          "type": "string",\r
+          "description": "VNF descriptor vendor ID"\r
+        },\r
+        "vnfdVersion": {\r
+          "type": "string",\r
+          "description": "VNF descriptor version"\r
+        },\r
+        "vnfVersion": {\r
+          "type": "string",\r
+          "description": "VNF Software version"\r
+        }\r
+      }\r
+    },\r
+    "VnfInstListInfo": {\r
+      "type": "array",\r
+      "items": {\r
+        "$ref": "#/definitions/VnfInstInfo"\r
+      }\r
+    },\r
+    "VnfInstInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "vnfInstanceId": {\r
+          "type": "string",\r
+          "description": "VNF instance ID"\r
+        },\r
+        "vnfInstanceName": {\r
+          "type": "string",\r
+          "description": "VNF instance name"\r
+        }\r
+      }\r
+    },\r
+    "VnfPkgImgListInfo": {\r
+      "type": "array",\r
+      "items": {\r
+        "$ref": "#/definitions/VnfPkgImgInfo"\r
+      }\r
+    },\r
+    "VnfPkgImgInfo": {\r
+      "type": "object",\r
+      "properties": {\r
+        "fileName": {\r
+          "type": "string",\r
+          "description": "image file name"\r
+        },\r
+        "imageUrl": {\r
+          "type": "string",\r
+          "description": "image file path in the csar or image url in external repository"\r
+        }\r
+      }\r
+    }\r
+  }\r
+}
\ No newline at end of file
diff --git a/catalog/swagger/views.py b/catalog/swagger/views.py
new file mode 100644 (file)
index 0000000..3dc4c75
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright 2016-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 json
+import logging
+import os
+import traceback
+
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+
+logger = logging.getLogger(__name__)
+
+
+class SwaggerJsonView(APIView):
+
+    def get(self, request):
+
+        json_file = os.path.join(os.path.dirname(__file__), 'vfc.catalog.swagger.json')
+        f = open(json_file)
+        json_data = json.JSONDecoder().decode(f.read())
+        f.close()
+
+        return Response(json_data)
+        
\ No newline at end of file
index 161624b..9d4d8f2 100644 (file)
@@ -18,6 +18,7 @@ from catalog.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL,
 urlpatterns = [
     url(r'^', include('catalog.samples.urls')),
     url(r'^', include('catalog.packages.urls')),
+    url(r'^', include('catalog.swagger.urls')),
 ]
 
 # regist to MSB when startup