mirror of
https://github.com/beego/bee.git
synced 2024-11-22 15:10:54 +00:00
add array type support in comment param
This commit is contained in:
parent
146200024c
commit
ca2f60c72d
24
g_docs.go
24
g_docs.go
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user