Seed code
[nonrtric/plt/sme.git] / 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
49 func getData(filename string) map[string]interface{} {
50         yamlFile, err := ioutil.ReadFile(*apiDir + "/" + filename)
51         if err != nil {
52                 log.Fatalf("Error reading yamlFile. #%v ", err)
53         }
54         m := make(map[string]interface{})
55         err = yaml.Unmarshal(yamlFile, m)
56         if err != nil {
57                 log.Fatalf("Unmarshal: %v", err)
58         }
59         return m
60 }
61
62 func writeFile(filename string, data map[string]interface{}) {
63         modCommon, err := yaml.Marshal(data)
64         if err != nil {
65                 log.Fatalf("Marshal: #%v ", err)
66         }
67         err = ioutil.WriteFile(*apiDir+"/"+filename, modCommon, 0644)
68         if err != nil {
69                 log.Fatalf("Error writing yamlFile. #%v ", err)
70         }
71 }