Swagger issue fixes from the Ericsson team:content-type extends the "application... 59/98959/3
authorhongyuzhao <zhao.hongyu@zte.com.cn>
Fri, 29 Nov 2019 08:58:52 +0000 (16:58 +0800)
committerhongyuzhao <zhao.hongyu@zte.com.cn>
Sat, 30 Nov 2019 03:21:02 +0000 (11:21 +0800)
Change-Id: Ib516dadf8430e5b4230ac1d51d936517e9cec8ba
Issue-ID: MODELING-288
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
catalog/packages/views/pnf_descriptor_views.py
catalog/packages/views/vnf_package_artifact_views.py
catalog/packages/views/vnf_package_subscription_views.py
catalog/packages/views/vnf_package_views.py
catalog/swagger/views.py

index 1fa03dc..4051e56 100644 (file)
@@ -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'])
index 56f3f2f..dde7585 100644 (file)
@@ -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",
index 8289275..7bf29de 100644 (file)
@@ -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)
index 2156e7b..6ff4f9f 100644 (file)
@@ -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],
index 4739188..93be679 100644 (file)
@@ -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"]