Update release notes for Service Manager and CapifCore (J-Release)
[nonrtric/plt/sme.git] / capifcore / internal / gentools / specificationfixer / specificationfixer.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2022: 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 import (
24         "flag"
25         "io/ioutil"
26         "log"
27
28         "gopkg.in/yaml.v2"
29 )
30
31 var apiDir *string
32
33 func main() {
34         apiDir = flag.String("apidir", "", "Directory containing API definitions to fix")
35         flag.Parse()
36
37         m := getData("TS29571_CommonData.yaml")
38         components := m["components"]
39         cMap := components.(map[interface{}]interface{})
40         schemas := cMap["schemas"].(map[interface{}]interface{})
41         snssaiExtensionData := schemas["SnssaiExtension"].(map[interface{}]interface{})
42         props := snssaiExtensionData["properties"].(map[interface{}]interface{})
43         wildcardSdData := props["wildcardSd"].(map[interface{}]interface{})
44         delete(wildcardSdData, "enum")
45
46         writeFile("TS29571_CommonData.yaml", m)
47
48         m = getData("TS29222_CAPIF_Security_API.yaml")
49         components = m["components"]
50         cMap = components.(map[interface{}]interface{})
51         schemas = cMap["schemas"].(map[interface{}]interface{})
52         accessTokenReq := schemas["AccessTokenReq"].(map[interface{}]interface{})
53         accessTokenReq["type"] = "object"
54
55         writeFile("TS29222_CAPIF_Security_API.yaml", m)
56 }
57
58 func getData(filename string) map[string]interface{} {
59         yamlFile, err := ioutil.ReadFile(*apiDir + "/" + filename)
60         if err != nil {
61                 log.Fatalf("Error reading yamlFile. #%v ", err)
62         }
63         m := make(map[string]interface{})
64         err = yaml.Unmarshal(yamlFile, m)
65         if err != nil {
66                 log.Fatalf("Unmarshal: %v", err)
67         }
68         return m
69 }
70
71 func writeFile(filename string, data map[string]interface{}) {
72         modCommon, err := yaml.Marshal(data)
73         if err != nil {
74                 log.Fatalf("Marshal: #%v ", err)
75         }
76         err = ioutil.WriteFile(*apiDir+"/"+filename, modCommon, 0644)
77         if err != nil {
78                 log.Fatalf("Error writing yamlFile. #%v ", err)
79         }
80 }