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

Merge pull request #458 from BusterMachine7/master

array的格式
This commit is contained in:
astaxie 2017-11-19 11:20:07 +08:00 committed by GitHub
commit 76a4feb17e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -614,10 +614,25 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error {
pp := strings.Split(p[2], ".")
typ := pp[len(pp)-1]
if len(pp) >= 2 {
isArray := false
if p[1] == "body" && strings.HasPrefix(p[2], "[]") {
p[2] = p[2][2:]
isArray = true
}
m, mod, realTypes := getModel(p[2])
if isArray {
para.Schema = &swagger.Schema{
Type: "array",
Items: &swagger.Schema{
Ref: "#/definitions/" + m,
},
}
} else {
para.Schema = &swagger.Schema{
Ref: "#/definitions/" + m,
}
}
if _, ok := modelsList[pkgpath+controllerName]; !ok {
modelsList[pkgpath+controllerName] = make(map[string]swagger.Schema)
}
@ -766,11 +781,21 @@ func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName s
appendModels(pkgpath, controllerName, realTypes)
}
if isArray {
if para.In == "body" {
para.Schema = &swagger.Schema{
Type: "array",
Items: &swagger.Schema{
Type: paraType,
Format: paraFormat,
},
}
} else {
para.Type = "array"
para.Items = &swagger.ParameterItems{
Type: paraType,
Format: paraFormat,
}
}
} else {
para.Type = paraType
para.Format = paraFormat