From: hongyuzhao Date: Fri, 29 Nov 2019 08:58:52 +0000 (+0800) Subject: Swagger issue fixes from the Ericsson team:content-type extends the "application... X-Git-Tag: 1.0.5~32 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=modeling%2Fetsicatalog.git;a=commitdiff_plain;h=06bfcce3f57176e6b428e43e8e411e245a5fa75e Swagger issue fixes from the Ericsson team:content-type extends the "application / octet-stream" Change-Id: Ib516dadf8430e5b4230ac1d51d936517e9cec8ba Issue-ID: MODELING-288 Signed-off-by: hongyuzhao --- diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py index 1fa03dc..4051e56 100644 --- a/catalog/packages/views/pnf_descriptor_views.py +++ b/catalog/packages/views/pnf_descriptor_views.py @@ -34,6 +34,7 @@ from catalog.packages.views.common import validate_data from catalog.pub.utils.syscomm import fun_name from catalog.pub.utils.values import ignore_case_get from .common import view_safe_call_with_log +from catalog.swagger.views import EtsiCatalogFileAutoSchema logger = logging.getLogger(__name__) @@ -121,6 +122,7 @@ def pnf_descriptors_rc(request): } ) @swagger_auto_schema( + auto_schema=EtsiCatalogFileAutoSchema, method='GET', operation_description="Fetch PNFD content", tags=[TAG_PNFD_API], @@ -131,7 +133,6 @@ def pnf_descriptors_rc(request): status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() }, - produces='application/octet-stream', operation_id='Fetch PNFD content' ) @api_view(http_method_names=['PUT', 'GET']) diff --git a/catalog/packages/views/vnf_package_artifact_views.py b/catalog/packages/views/vnf_package_artifact_views.py index 56f3f2f..dde7585 100644 --- a/catalog/packages/views/vnf_package_artifact_views.py +++ b/catalog/packages/views/vnf_package_artifact_views.py @@ -23,6 +23,7 @@ from rest_framework.views import APIView from catalog.packages.biz.vnf_pkg_artifacts import FetchVnfPkgArtifact from catalog.packages.const import TAG_VNF_PACKAGE_API from .common import view_safe_call_with_log +from catalog.swagger.views import EtsiCatalogFileAutoSchema logger = logging.getLogger(__name__) @@ -39,6 +40,7 @@ VALID_FILTERS = [ class FetchVnfPkgmArtifactsView(APIView): @swagger_auto_schema( + auto_schema=EtsiCatalogFileAutoSchema, tags=[TAG_VNF_PACKAGE_API], responses={ status.HTTP_200_OK: openapi.Response("Return the artifact file", diff --git a/catalog/packages/views/vnf_package_subscription_views.py b/catalog/packages/views/vnf_package_subscription_views.py index 8289275..7bf29de 100644 --- a/catalog/packages/views/vnf_package_subscription_views.py +++ b/catalog/packages/views/vnf_package_subscription_views.py @@ -27,7 +27,7 @@ from catalog.packages.serializers.response import ProblemDetailsSerializer from catalog.packages.serializers.vnf_pkg_subscription import PkgmSubscriptionRequestSerializer from catalog.packages.serializers.vnf_pkg_subscription import PkgmSubscriptionSerializer from catalog.packages.serializers.vnf_pkg_subscription import PkgmSubscriptionsSerializer -from catalog.packages.views.common import validate_data +from catalog.packages.views.common import validate_data, validate_req_data from catalog.pub.exceptions import BadRequestException from catalog.pub.exceptions import VnfPkgSubscriptionException from .common import view_safe_call_with_log @@ -51,14 +51,15 @@ class CreateQuerySubscriptionView(APIView): request_body=PkgmSubscriptionRequestSerializer, responses={ status.HTTP_201_CREATED: PkgmSubscriptionSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + status.HTTP_400_BAD_REQUEST: ProblemDetailsSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) @view_safe_call_with_log(logger=logger) def post(self, request): logger.debug("Create VNF package Subscription> %s" % request.data) - vnf_pkg_subscription_request = validate_data(request.data, PkgmSubscriptionRequestSerializer) + vnf_pkg_subscription_request = validate_req_data(request.data, PkgmSubscriptionRequestSerializer) data = CreateSubscription(vnf_pkg_subscription_request.data).do_biz() subscription_info = validate_data(data, PkgmSubscriptionSerializer) return Response(data=subscription_info.data, status=status.HTTP_201_CREATED) diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py index 2156e7b..6ff4f9f 100644 --- a/catalog/packages/views/vnf_package_views.py +++ b/catalog/packages/views/vnf_package_views.py @@ -32,6 +32,7 @@ from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer from catalog.packages.serializers.vnf_pkg_infos import VnfPkgInfosSerializer from .common import validate_data, validate_req_data from .common import view_safe_call_with_log +from catalog.swagger.views import EtsiCatalogFileAutoSchema logger = logging.getLogger(__name__) @@ -77,6 +78,7 @@ def vnf_packages_rc(request): @swagger_auto_schema( + auto_schema=EtsiCatalogFileAutoSchema, method="GET", operation_description="Read VNFD of an on-boarded VNF package", tags=[TAG_VNF_PACKAGE_API], @@ -90,7 +92,6 @@ def vnf_packages_rc(request): status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response("Internal error", schema=openapi.Schema(type=openapi.TYPE_STRING)) }, - produces='application/octet-stream', operation_id='VNFD of an on-boarded VNF package' ) @api_view(http_method_names=["GET"]) @@ -118,6 +119,7 @@ def vnfd_rd(request, **kwargs): } ) @swagger_auto_schema( + auto_schema=EtsiCatalogFileAutoSchema, method="GET", operation_description="Fetch VNF package content", tags=[TAG_VNF_PACKAGE_API], diff --git a/catalog/swagger/views.py b/catalog/swagger/views.py index 4739188..93be679 100644 --- a/catalog/swagger/views.py +++ b/catalog/swagger/views.py @@ -17,6 +17,7 @@ import os from rest_framework.response import Response from rest_framework.views import APIView +from drf_yasg.inspectors import SwaggerAutoSchema class SwaggerJsonView(APIView): @@ -26,3 +27,9 @@ class SwaggerJsonView(APIView): json_data = json.JSONDecoder().decode(f.read()) f.close() return Response(json_data) + + +class EtsiCatalogFileAutoSchema(SwaggerAutoSchema): + def get_produces(self): + super(EtsiCatalogFileAutoSchema, self).get_produces() + return ["application/octet-stream", "application/json"]