Merge "Fix VFC swagger bug"
[vfc/nfvo/lcm.git] / lcm / swagger / views.py
1 # Copyright 2016-2017 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import json
15 import logging
16 import os
17 import traceback
18
19 from rest_framework import status
20 from rest_framework.response import Response
21 from rest_framework.views import APIView
22
23
24 logger = logging.getLogger(__name__)
25
26
27 class SwaggerJsonView(APIView):
28
29     def get(self, request):
30
31         json_file = os.path.join(os.path.dirname(__file__), 'vfc.nslcm.swagger.json')
32         f = open(json_file)
33         json_data = json.JSONDecoder().decode(f.read())
34         f.close()
35
36         json_file = os.path.join(os.path.dirname(__file__), 'vfc.vnflcm.swagger.json')
37         f = open(json_file)
38         json_data_temp = json.JSONDecoder().decode(f.read())
39         f.close()
40
41         json_data["paths"].update(json_data_temp["paths"])
42         json_data["definitions"].update(json_data_temp["definitions"])
43
44         json_file = os.path.join(os.path.dirname(__file__), 'vfc.vllcm.swagger.json')
45         f = open(json_file)
46         json_data_temp = json.JSONDecoder().decode(f.read())
47         f.close()
48
49         json_data["paths"].update(json_data_temp["paths"])
50         json_data["definitions"].update(json_data_temp["definitions"])
51
52
53         json_file = os.path.join(os.path.dirname(__file__), 'vfc.sfclcm.swagger.json')
54         f = open(json_file)
55         json_data_temp = json.JSONDecoder().decode(f.read())
56         f.close()
57
58         json_data["paths"].update(json_data_temp["paths"])
59         json_data["definitions"].update(json_data_temp["definitions"])
60
61
62         json_file = os.path.join(os.path.dirname(__file__), 'vfc.others.swagger.json')
63         f = open(json_file)
64         json_data_temp = json.JSONDecoder().decode(f.read())
65         f.close()
66
67         json_data_jobtemp=json_data["paths"]["/jobs/{jobId}"]
68         json_data["paths"].update(json_data_temp["paths"])
69         json_data["paths"]["/jobs/{jobId}"].update(json_data_jobtemp)
70         json_data["definitions"].update(json_data_temp["definitions"])
71
72         return Response(json_data)
73
74     
75