Re-enable participant links & checks after first build of i-release docs
[nonrtric/plt/rappmanager.git] / scripts / install / scripts / init / getsmeswagger.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2023: Nordix Foundation
6 //   %%
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
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
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===================================
19 //
20
21 package main
22
23
24 import (
25         "github.com/getkin/kin-openapi/openapi3"
26         log "github.com/sirupsen/logrus"
27         "gopkg.in/yaml.v3"
28         "encoding/json"
29          "io/ioutil"
30
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"
37 )
38
39 func main() {
40         var swagger *openapi3.T
41         var err error
42
43         swagger,err = providermanagementapi.GetSwagger()
44     if err == nil {
45         generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Provider_Management_API.yaml")
46     }
47
48     swagger,err = publishserviceapi.GetSwagger()
49     if err == nil {
50         generateSwaggerYaml(swagger, "TS29222_CAPIF_Publish_Service_API.yaml")
51     }
52
53     swagger,err = invokermanagementapi.GetSwagger()
54     if err == nil {
55         generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Invoker_Management_API.yaml")
56     }
57
58     swagger,err = common.GetSwagger()
59     if err == nil {
60         generateSwaggerYaml(swagger, "CommonData.yaml")
61     }
62
63     swagger,err = common29122.GetSwagger()
64     if err == nil {
65         generateSwaggerYaml(swagger, "TS29122_CommonData.yaml")
66     }
67
68     swagger,err = common29571.GetSwagger()
69     if err == nil {
70         generateSwaggerYaml(swagger, "TS29571_CommonData.yaml")
71     }
72 }
73
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)
78     }
79
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)
83         log.Fatal(err)
84     }
85
86     yamldataarr, yamldataarrerr := yaml.Marshal(&data)
87     if yamldataarrerr != nil {
88         log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
89     }
90
91     err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
92     if err2 != nil {
93         log.Fatalf("Error writing provider yaml \n: %s", err2)
94     }
95 }