X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fgentools%2Fenumfixer%2Fenumfixer.go;h=e7228753293c44ada01c2ffd5308ff3dcd6ca7ed;hb=37b5fcbb802f06442a9c08c94e709080a747f7ad;hp=b44c55c4d97e62834e24a2325caa9d00f8ed9e77;hpb=c9e08b2a2f647f9f870040570c5e71305f0fb5d2;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/gentools/enumfixer/enumfixer.go b/capifcore/internal/gentools/enumfixer/enumfixer.go index b44c55c..e722875 100644 --- a/capifcore/internal/gentools/enumfixer/enumfixer.go +++ b/capifcore/internal/gentools/enumfixer/enumfixer.go @@ -63,51 +63,53 @@ func fixEnums(path string, info os.FileInfo, _ error) error { components := m["components"] if components != nil { cMap := components.(map[interface{}]interface{}) - schemas := cMap["schemas"].(map[interface{}]interface{}) - for typeName, typeDef := range schemas { - tDMap := typeDef.(map[interface{}]interface{}) - anyOf, ok := tDMap["anyOf"] - if ok { - aOSlice := anyOf.([]interface{}) - correctEnum := Enum{} - mapInterface := aOSlice[0].(map[interface{}]interface{}) - enumInterface := mapInterface["enum"] - if enumInterface != nil { - is := enumInterface.([]interface{}) - var enumVals []string - for i := 0; i < len(is); i++ { - if reflect.TypeOf(is[i]).Kind() == reflect.String { - enumVals = append(enumVals, is[i].(string)) + if _, ok := cMap["schemas"].(map[interface{}]interface{}); ok { + schemas := cMap["schemas"].(map[interface{}]interface{}) + for typeName, typeDef := range schemas { + tDMap := typeDef.(map[interface{}]interface{}) + anyOf, ok := tDMap["anyOf"] + if ok { + aOSlice := anyOf.([]interface{}) + correctEnum := Enum{} + mapInterface := aOSlice[0].(map[interface{}]interface{}) + enumInterface := mapInterface["enum"] + if enumInterface != nil { + is := enumInterface.([]interface{}) + var enumVals []string + for i := 0; i < len(is); i++ { + if reflect.TypeOf(is[i]).Kind() == reflect.String { + enumVals = append(enumVals, is[i].(string)) - } else if reflect.TypeOf(is[1]).Kind() == reflect.Int { - enumVals = append(enumVals, strconv.Itoa(is[i].(int))) + } else if reflect.TypeOf(is[1]).Kind() == reflect.Int { + enumVals = append(enumVals, strconv.Itoa(is[i].(int))) + } } - } - correctEnum.Enum = enumVals - correctEnum.Type = "string" - description := tDMap["description"] - if description != nil { - correctEnum.Description = description.(string) - } else { - if aOSlice[1] != nil { - mapInterface = aOSlice[1].(map[interface{}]interface{}) - description := mapInterface["description"] - if description != nil { - correctEnum.Description = description.(string) + correctEnum.Enum = enumVals + correctEnum.Type = "string" + description := tDMap["description"] + if description != nil { + correctEnum.Description = description.(string) + } else { + if aOSlice[1] != nil { + mapInterface = aOSlice[1].(map[interface{}]interface{}) + description := mapInterface["description"] + if description != nil { + correctEnum.Description = description.(string) + } } } + schemas[typeName] = correctEnum } - schemas[typeName] = correctEnum } } - } - modM, err := yaml.Marshal(m) - if err != nil { - log.Printf("yamlFile. Get err #%v ", err) - } - err = ioutil.WriteFile(path, modM, 0644) - if err != nil { - log.Printf("yamlFile. Get err #%v ", err) + modM, err := yaml.Marshal(m) + if err != nil { + log.Printf("yamlFile. Get err #%v ", err) + } + err = ioutil.WriteFile(path, modM, 0644) + if err != nil { + log.Printf("yamlFile. Get err #%v ", err) + } } } }