2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
25 "github.com/getkin/kin-openapi/openapi3"
26 log "github.com/sirupsen/logrus"
31 "oransc.org/nonrtric/capifcore/internal/invokermanagementapi"
32 "oransc.org/nonrtric/capifcore/internal/providermanagementapi"
33 "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
34 "oransc.org/nonrtric/capifcore/internal/common"
35 "oransc.org/nonrtric/capifcore/internal/common29122"
36 "oransc.org/nonrtric/capifcore/internal/common29571"
40 var swagger *openapi3.T
43 swagger,err = providermanagementapi.GetSwagger()
45 generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Provider_Management_API.yaml")
48 swagger,err = publishserviceapi.GetSwagger()
50 generateSwaggerYaml(swagger, "TS29222_CAPIF_Publish_Service_API.yaml")
53 swagger,err = invokermanagementapi.GetSwagger()
55 generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Invoker_Management_API.yaml")
58 swagger,err = common.GetSwagger()
60 generateSwaggerYaml(swagger, "CommonData.yaml")
63 swagger,err = common29122.GetSwagger()
65 generateSwaggerYaml(swagger, "TS29122_CommonData.yaml")
68 swagger,err = common29571.GetSwagger()
70 generateSwaggerYaml(swagger, "TS29571_CommonData.yaml")
74 func generateSwaggerYaml(swagger *openapi3.T, filename string) {
75 jsondataarr, jsondataarrerr := json.Marshal(&swagger)
76 if jsondataarrerr != nil {
77 log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr)
80 var data map[string]interface{}
81 if err := json.Unmarshal(jsondataarr, &data); err != nil {
82 log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr)
86 yamldataarr, yamldataarrerr := yaml.Marshal(&data)
87 if yamldataarrerr != nil {
88 log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
91 err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
93 log.Fatalf("Error writing provider yaml \n: %s", err2)