From: maopengzhang Date: Thu, 24 Aug 2017 11:46:56 +0000 (+0800) Subject: swagger supports for catalog1 X-Git-Tag: v1.0.0~94 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=eb613524f634d225a16e90e7d32e81f76375e4d5;p=vfc%2Fnfvo%2Fcatalog.git swagger supports for catalog1 Support swagger file in catalog Change-Id: Ieb2778fd4239cdae66d660f536f930e5d0011db1 Issue-ID: VFC-145 Signed-off-by: maopengzhang --- diff --git a/catalog/settings.py b/catalog/settings.py index 629f68a1..3c13adeb 100644 --- a/catalog/settings.py +++ b/catalog/settings.py @@ -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 index 00000000..49c7b944 --- /dev/null +++ b/catalog/swagger/__init__.py @@ -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 index 00000000..40aaea70 --- /dev/null +++ b/catalog/swagger/tests.py @@ -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 index 00000000..b807b887 --- /dev/null +++ b/catalog/swagger/urls.py @@ -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 index 00000000..ece4cd4d --- /dev/null +++ b/catalog/swagger/vfc.catalog.swagger.json @@ -0,0 +1,510 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "ONAP VFC Catalog Rest API", + "description": "VFC Catalog Management API.", + "contact": { + "name": "ONAP VFC team", + "email": "onap-discuss@lists.onap.org", + "url": "https://gerrit.onap.org/r/#/admin/projects/vfc/nfvo/catalog" + } + }, + "basePath": "/api/catalog/v1", + "schemes": [ + "http", + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/nspackages": { + "get": { + "tags": [ + "nspackage" + ], + "summary": "query ns packages info", + "description": "query ns packages info", + "operationId": "query_ns_packages", + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/NsPkgListInfo" + } + }, + "500": { + "description": "internal error" + } + } + }, + "post": { + "tags": [ + "nspackage" + ], + "summary": "ns package distribute", + "description": "ns package distribute", + "operationId": "ns_pkg_distribute", + "parameters": [ + { + "in": "body", + "name": "body", + "description": "distribute request param", + "required": true, + "schema": { + "$ref": "#/definitions/NsPkgDistributeRequest" + } + } + ], + "responses": { + "202": { + "description": "", + "schema": { + "$ref": "#/definitions/NsPkgDistributeResponse" + } + }, + "500": { + "description": "internal error" + } + } + } + }, + "/nspackages/{csarId}": { + "get": { + "tags": [ + "nspackage" + ], + "summary": "query ns package info", + "description": "query ns package info via ns package csarId", + "operationId": "query_ns_package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "csarId", + "in": "path", + "description": "csar id of ns package", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/NsPkgDetailInfo" + } + }, + "500": { + "description": "internal error" + } + } + }, + "delete": { + "tags": [ + "nspackage" + ], + "summary": "delete ns pkg", + "description": "delete ns pkg", + "operationId": "delete_ns_pkg", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "csarId", + "in": "path", + "description": "csar id of ns package", + "required": true, + "type": "string" + } + ], + "responses": { + "202": { + "description": "", + "schema": { + "$ref": "#/definitions/NsPkgDelResponse" + } + }, + "500": { + "description": "internal error" + } + } + } + }, + "/vnfpackages": { + "get": { + "tags": [ + "vnfpackage" + ], + "summary": "query vnf packages info", + "description": "query vnf packages info", + "operationId": "query_vnf_packages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/VnfPkgListInfo" + } + }, + "500": { + "description": "internal error" + } + } + }, + "post": { + "tags": [ + "vnfpackage" + ], + "summary": "vnf package distribute", + "description": "vnf package distribute", + "operationId": "vnf_pkg_distribute", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "distribute request param", + "required": true, + "schema": { + "$ref": "#/definitions/VnfPkgDistributeRequest" + } + } + ], + "responses": { + "202": { + "description": "", + "schema": { + "$ref": "#/definitions/VnfPkgDistributeResponse" + } + }, + "500": { + "description": "internal error" + } + } + } + }, + "/vnfpackages/{csarId}": { + "get": { + "tags": [ + "vnfpackage" + ], + "summary": "query vnf package info", + "description": "query one vnf package info via vnf package csarId", + "operationId": "query_vnf_package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "csarId", + "in": "path", + "description": "csar id of vnf package", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/VnfPkgDetailInfo" + } + }, + "500": { + "description": "internal error" + } + } + }, + "delete": { + "tags": [ + "vnfpackage" + ], + "summary": "delete vnf package", + "description": "delete vnf package", + "operationId": "delete_vnf_package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "csarId", + "in": "path", + "description": "csar id of vnf package", + "required": true, + "type": "string" + } + ], + "responses": { + "202": { + "description": "", + "schema": { + "$ref": "#/definitions/VnfPkgDelResponse" + } + }, + "500": { + "description": "internal error" + } + } + } + } + }, + "definitions": { + "NsPkgDistributeRequest": { + "type": "object", + "properties": { + "csarId": { + "type": "string", + "description": "network service package id, UUID" + } + } + }, + "NsPkgDistributeResponse": { + "type": "object", + "properties": { + "status": { + "type": "string", + "description": "Operation status. value is success or failed" + }, + "statusDescription": { + "type": "string", + "description": "description about the operation result" + }, + "errorCode": { + "type": "string", + "description": "If the status is failed, the errorcode will be returned" + } + } + }, + "NsPkgDelResponse": { + "type": "object", + "properties": { + "status": { + "type": "string", + "description": "Operation status. value is success or failed" + }, + "statusDescription": { + "type": "string", + "description": "description about the operation result" + }, + "errorCode": { + "type": "string", + "description": "If the status is failed, the errorcode will be returned" + } + } + }, + "NsPkgListInfo": { + "type": "array", + "items": { + "$ref": "#/definitions/NsPkgInfo" + } + }, + "NsPkgDetailInfo": { + "type": "object", + "properties": { + "csarId": { + "type": "string" + }, + "NsPackageInfo": { + "$ref": "#/definitions/NsPkgInfo" + }, + "NsInstanceInfo": { + "$ref": "#/definitions/NsInstListInfo" + } + } + }, + "NsPkgInfo": { + "type": "object", + "properties": { + "csarId": { + "type": "string", + "description": "network service package id, UUID" + }, + "nsdId": { + "type": "string", + "description": "network service descriptor ID" + }, + "nsdProvider": { + "type": "string", + "description": "network service designer name" + }, + "nsdVersion": { + "type": "string", + "description": "network service descriptor version" + } + } + }, + "NsInstListInfo": { + "type": "array", + "items": { + "$ref": "#/definitions/NsInstInfo" + } + }, + "NsInstInfo": { + "type": "object", + "properties": { + "nsInstanceId": { + "type": "string", + "description": "network service instance ID" + }, + "nsInstanceName": { + "type": "string", + "description": "network service instance name" + } + } + }, + "VnfPkgDistributeRequest": { + "type": "object", + "properties": { + "csarId": { + "type": "string", + "description": "vnf package id, UUID" + } + } + }, + "VnfPkgDistributeResponse": { + "type": "object", + "properties": { + "jobId": { + "type": "string", + "description": "VNF package distribute job ID" + } + } + }, + "VnfPkgDelResponse": { + "type": "object", + "properties": { + "status": { + "type": "string", + "description": "Operation status. value is success or failed" + }, + "statusDescription": { + "type": "string", + "description": "description about the operation result" + }, + "errorCode": { + "type": "string", + "description": "If the status is failed, the errorcode will be returned" + } + } + }, + "VnfPkgListInfo": { + "type": "array", + "items": { + "$ref": "#/definitions/VnfPkgInfo" + } + }, + "VnfPkgDetailInfo": { + "type": "object", + "properties": { + "csarId": { + "type": "string", + "description": "vnf package id, UUID" + }, + "packageInfo": { + "$ref": "#/definitions/VnfPkgInfo" + }, + "imageInfo": { + "$ref": "#/definitions/VnfPkgImgListInfo" + }, + "vnfInstanceInfo": { + "$ref": "#/definitions/VnfInstListInfo" + } + } + }, + "VnfPkgInfo": { + "type": "object", + "description": "vnf package infomation", + "properties": { + "csarId": { + "type": "string", + "description": "vnf package id, UUID" + }, + "vnfdId": { + "type": "string", + "description": "VNF descriptor ID" + }, + "vnfdProvider": { + "type": "string", + "description": "VNF descriptor vendor ID" + }, + "vnfdVersion": { + "type": "string", + "description": "VNF descriptor version" + }, + "vnfVersion": { + "type": "string", + "description": "VNF Software version" + } + } + }, + "VnfInstListInfo": { + "type": "array", + "items": { + "$ref": "#/definitions/VnfInstInfo" + } + }, + "VnfInstInfo": { + "type": "object", + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "VNF instance ID" + }, + "vnfInstanceName": { + "type": "string", + "description": "VNF instance name" + } + } + }, + "VnfPkgImgListInfo": { + "type": "array", + "items": { + "$ref": "#/definitions/VnfPkgImgInfo" + } + }, + "VnfPkgImgInfo": { + "type": "object", + "properties": { + "fileName": { + "type": "string", + "description": "image file name" + }, + "imageUrl": { + "type": "string", + "description": "image file path in the csar or image url in external repository" + } + } + } + } +} \ No newline at end of file diff --git a/catalog/swagger/views.py b/catalog/swagger/views.py new file mode 100644 index 00000000..3dc4c750 --- /dev/null +++ b/catalog/swagger/views.py @@ -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 diff --git a/catalog/urls.py b/catalog/urls.py index 161624b7..9d4d8f26 100644 --- a/catalog/urls.py +++ b/catalog/urls.py @@ -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