From aa92fc4854c3757160b00b1dec5192b558f41b9a Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 24 Jun 2014 12:06:45 +0800 Subject: [PATCH] bee 1.1.2 --- bee.go | 2 +- g_docs.go | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bee.go b/bee.go index bcf3380..bac171a 100644 --- a/bee.go +++ b/bee.go @@ -25,7 +25,7 @@ import ( "strings" ) -const version = "1.1.1" +const version = "1.1.2" type Command struct { // Run runs the command. diff --git a/g_docs.go b/g_docs.go index afae895..552b63e 100644 --- a/g_docs.go +++ b/g_docs.go @@ -377,6 +377,8 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat panic(controllerName + " " + funcName + " has no object") } cmpath, m, mod, realTypes := getModel(st[2]) + //ll := strings.Split(st[2], ".") + //opts.Type = ll[len(ll)-1] rs.ResponseModel = m if _, ok := modelsList[pkgpath+controllerName]; !ok { modelsList[pkgpath+controllerName] = make([]swagger.Model, 0) @@ -395,7 +397,8 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat } para.Name = p[0] para.ParamType = p[1] - para.DataType = p[2] + pp := strings.Split(p[2], ".") + para.DataType = pp[len(pp)-1] if len(p) > 4 { para.Required, _ = strconv.ParseBool(p[3]) para.Description = p[4] @@ -562,7 +565,6 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType } } } - fmt.Println(str) if m.Id == "" { ColorLog("can't find the object: %v", str) os.Exit(1) @@ -584,6 +586,10 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType string) { return true, fmt.Sprint(arr.Elt) } } else { + switch t := f.Type.(type) { + case *ast.StarExpr: + return false, fmt.Sprint(t.X) + } return false, fmt.Sprint(f.Type) } } @@ -599,13 +605,13 @@ func isBasicType(Type string) bool { // refer to builtin.go var basicTypes = []string{ - "bool", "byte", + "bool", "uint", "uint8", "uint16", "uint32", "uint64", "int", "int8", "int16", "int32", "int64", "float32", "float64", "string", - // "complex64", "complex128", - // "byte", "rune", "uintptr", + "complex64", "complex128", + "byte", "rune", "uintptr", } // regexp get json tag @@ -621,7 +627,8 @@ func grepJsonTag(tag string) string { // append models func appendModels(cmpath, pkgpath, controllerName string, realTypes []string) { for _, realType := range realTypes { - if realType != "" && strings.HasPrefix(realType, "[]") && !isBasicType(strings.TrimLeft(realType, "[]")) { + if realType != "" && !isBasicType(strings.TrimLeft(realType, "[]")) && + !strings.HasPrefix(realType, "map") && !strings.HasPrefix(realType, "&") { if cmpath != "" { cmpath = strings.Join(strings.Split(cmpath, "/"), ".") + "." }