1
0
mirror of https://github.com/beego/bee.git synced 2024-11-25 15:00:55 +00:00

Made the example value for enum type sensitive.

This commit is contained in:
Muxian Wu 2018-03-15 18:05:37 +08:00
parent be6186155f
commit 611eecc204

View File

@ -947,7 +947,7 @@ func parseIdent(st *ast.Ident, k string, m *swagger.Schema, astPkgs []*ast.Packa
m.Format = typeFormat[1] m.Format = typeFormat[1]
} }
enums := make(map[int]string) enums := make(map[int]string)
enumValues := make(map[int]string) enumValues := make(map[int]interface{})
for _, pkg := range astPkgs { for _, pkg := range astPkgs {
for _, fl := range pkg.Files { for _, fl := range pkg.Files {
for _, obj := range fl.Scope.Objects { for _, obj := range fl.Scope.Objects {
@ -975,7 +975,25 @@ func parseIdent(st *ast.Ident, k string, m *swagger.Schema, astPkgs []*ast.Packa
continue continue
} }
enums[int(val.Pos())] = fmt.Sprintf("%s = %s", vs.Names[i].Name, v.Value) enums[int(val.Pos())] = fmt.Sprintf("%s = %s", vs.Names[i].Name, v.Value)
enumValues[int(val.Pos())] = v.Value switch v.Kind {
case token.INT:
vv, err := strconv.Atoi(v.Value)
if err != nil {
beeLogger.Log.Warnf("Unknown type with BasicLit to int: %v\n", v.Value)
continue
}
enumValues[int(val.Pos())] = vv
case token.FLOAT:
vv, err := strconv.ParseFloat(v.Value, 64)
if err != nil {
beeLogger.Log.Warnf("Unknown type with BasicLit to int: %v\n", v.Value)
continue
}
enumValues[int(val.Pos())] = vv
default:
enumValues[int(val.Pos())] = strings.Trim(v.Value, `"`)
}
} }
} }
} }