1
0
mirror of https://github.com/beego/bee.git synced 2024-11-26 06:21:34 +00:00

add array type support in comment param

This commit is contained in:
tnextday 2016-08-20 11:17:30 +08:00
parent 146200024c
commit ca2f60c72d

View File

@ -442,16 +442,33 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
modelsList[pkgpath+controllerName][typ] = mod modelsList[pkgpath+controllerName][typ] = mod
appendModels(cmpath, pkgpath, controllerName, realTypes) appendModels(cmpath, pkgpath, controllerName, realTypes)
} else { } else {
isArray := false
paraType := ""
paraFormat := ""
if strings.HasPrefix(typ, "[]") {
typ = typ[2:]
isArray = true
}
if typ == "string" || typ == "number" || typ == "integer" || typ == "boolean" || if typ == "string" || typ == "number" || typ == "integer" || typ == "boolean" ||
typ == "array" || typ == "file" { typ == "array" || typ == "file" {
para.Type = typ paraType = typ
} else if sType, ok := basicTypes[typ]; ok { } else if sType, ok := basicTypes[typ]; ok {
typeFormat := strings.Split(sType, ":") typeFormat := strings.Split(sType, ":")
para.Type = typeFormat[0] paraType = typeFormat[0]
para.Format = typeFormat[1] paraFormat = typeFormat[1]
} else { } else {
fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param type: %s\n", controllerName, funcName, typ) fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param type: %s\n", controllerName, funcName, typ)
} }
if isArray {
para.Type = "array"
para.Items = &swagger.ParameterItems{
Type: paraType,
Format: paraFormat,
}
} else {
para.Type = paraType
para.Format = paraFormat
}
} }
if len(p) > 4 { if len(p) > 4 {
para.Required, _ = strconv.ParseBool(p[3]) para.Required, _ = strconv.ParseBool(p[3])
@ -614,7 +631,6 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
Type: typeFormat[0], Type: typeFormat[0],
Format: typeFormat[1], Format: typeFormat[1],
} }
} else { } else {
mp.Items = &swagger.Propertie{ mp.Items = &swagger.Propertie{
Ref: "#/definitions/" + realType, Ref: "#/definitions/" + realType,