Generate from 5.12.72 fields

This commit is contained in:
Paul Tyng
2020-05-20 22:00:58 -04:00
parent 3d21ebbab0
commit 8e63bffebb
13 changed files with 1180 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ var fieldReps = []replacement{
{"Pd", "PD"},
{"Pmf", "PMF"},
{"Qos", "QOS"},
{"Radiusprofile", "RADIUSProfile"},
{"Radius", "RADIUS"},
{"Ssid", "SSID"},
{"Startdate", "StartDate"},
@@ -75,6 +76,7 @@ var fileReps = []replacement{
{"Dhcp", "DHCP"},
{"Wlan", "WLAN"},
{"NetworkConf", "Network"},
{"RadiusProfile", "RADIUSProfile"},
}
func cleanName(name string, reps []replacement) string {
@@ -118,6 +120,10 @@ func main() {
continue
}
if name == "Wall.json" {
continue
}
name = name[:len(name)-len(ext)]
urlPath := strings.ToLower(name)
@@ -325,7 +331,7 @@ func normalizeValidation(re string) string {
return re
}
func typeFromValidation(validation interface{}) (string, string, bool, error) {
func typeFromValidation(validation interface{}) (ty string, comment string, omitempty bool, err error) {
switch validation := validation.(type) {
case []interface{}:
if len(validation) == 0 {
@@ -339,6 +345,28 @@ func typeFromValidation(validation interface{}) (string, string, bool, error) {
return "", "", false, err
}
return fmt.Sprintf("[]%s", elementType), elementComment, true, nil
case map[string]interface{}:
fieldNames := []string{}
fieldCodes := map[string]string{}
for name, fv := range validation {
fieldNames = append(fieldNames, name)
fieldCode, err := generateField(name, fv)
if err != nil {
return "", "", false, err
}
fieldCodes[name] = fieldCode
}
// TODO: sort by normalized name, not this name
sort.Strings(fieldNames)
code := "struct {\n"
for _, name := range fieldNames {
code += fieldCodes[name] + "\n"
}
code += "\n}"
return code, "", false, nil
case string:
comment := validation
normalized := normalizeValidation(validation)