From 254174eda61f27a545d0a0880afbb499d4dcbc93 Mon Sep 17 00:00:00 2001 From: zhangyanzhe Date: Wed, 19 Jul 2017 14:42:46 +0800 Subject: [PATCH 1/4] array format --- generate/swaggergen/g_docs.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index be54679..061b9f8 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -612,10 +612,25 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { pp := strings.Split(p[2], ".") typ := pp[len(pp)-1] if len(pp) >= 2 { - m, mod, realTypes := getModel(p[2]) - para.Schema = &swagger.Schema{ - Ref: "#/definitions/" + m, + isArray := false + if p[1] == "body" || p[1] == "formData" || 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) } @@ -762,10 +777,12 @@ func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName s appendModels(pkgpath, controllerName, realTypes) } if isArray { - para.Type = "array" - para.Items = &swagger.ParameterItems{ - Type: paraType, - Format: paraFormat, + para.Schema = &swagger.Schema{ + Type: "array", + Items: &swagger.Schema{ + Type: paraType, + Format: paraFormat, + }, } } else { para.Type = paraType From 2b04261f9cd4e7079dd4ce3babd1ad729472edfb Mon Sep 17 00:00:00 2001 From: zhangyanzhe Date: Wed, 19 Jul 2017 14:47:19 +0800 Subject: [PATCH 2/4] array format --- generate/swaggergen/g_docs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 061b9f8..6c05489 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -613,7 +613,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { typ := pp[len(pp)-1] if len(pp) >= 2 { isArray := false - if p[1] == "body" || p[1] == "formData" || strings.HasPrefix(p[2], "[]") { + if (p[1] == "body" || p[1] == "formData") && strings.HasPrefix(p[2], "[]") { p[2] = p[2][2:] isArray = true } From d0b3ede4ec297c4d9838af1395074bb01ea28417 Mon Sep 17 00:00:00 2001 From: zhangyanzhe Date: Wed, 19 Jul 2017 15:38:04 +0800 Subject: [PATCH 3/4] array format --- generate/swaggergen/g_docs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 6c05489..922b93d 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -613,7 +613,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { typ := pp[len(pp)-1] if len(pp) >= 2 { isArray := false - if (p[1] == "body" || p[1] == "formData") && strings.HasPrefix(p[2], "[]") { + if p[1] == "body" && strings.HasPrefix(p[2], "[]") { p[2] = p[2][2:] isArray = true } From 58bfa5c1ec37231cb532af06b89ebaebef845167 Mon Sep 17 00:00:00 2001 From: zhangyanzhe Date: Wed, 19 Jul 2017 15:49:54 +0800 Subject: [PATCH 4/4] array format --- generate/swaggergen/g_docs.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 922b93d..441bba9 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -777,12 +777,20 @@ func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName s appendModels(pkgpath, controllerName, realTypes) } if isArray { - para.Schema = &swagger.Schema{ - Type: "array", - Items: &swagger.Schema{ + 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