From ac1bf161fcbb3bd2b1fc6636111f6a0a16562aba Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 17:38:26 +0800 Subject: [PATCH 1/6] generate gocs support go buildin type in comment param --- g_docs.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/g_docs.go b/g_docs.go index 005204d..a2b5ce5 100644 --- a/g_docs.go +++ b/g_docs.go @@ -426,6 +426,12 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat if typ == "string" || typ == "number" || typ == "integer" || typ == "boolean" || typ == "array" || typ == "file" { para.Type = typ + } else if sType, ok := basicTypes[typ]; ok { + typeFormat := strings.Split(sType, ":") + para.Type = typeFormat[0] + para.Format = typeFormat[1] + }else { + fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param type: %s\n", controllerName, funcName, typ) } } if len(p) > 4 { From 985c18a314b42bce903cced3811d9afdc0ba3cd0 Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 17:40:59 +0800 Subject: [PATCH 2/6] go format --- g_docs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g_docs.go b/g_docs.go index a2b5ce5..b6d01c3 100644 --- a/g_docs.go +++ b/g_docs.go @@ -430,7 +430,7 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat typeFormat := strings.Split(sType, ":") para.Type = typeFormat[0] para.Format = typeFormat[1] - }else { + } else { fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param type: %s\n", controllerName, funcName, typ) } } From 07df26c7b6a68ccecf3d94c76b3d76a76a40b410 Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 18:21:23 +0800 Subject: [PATCH 3/6] add param location checker in generate gocs --- g_docs.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/g_docs.go b/g_docs.go index b6d01c3..0233650 100644 --- a/g_docs.go +++ b/g_docs.go @@ -409,7 +409,21 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat panic(controllerName + "_" + funcName + "'s comments @Param at least should has 4 params") } para.Name = p[0] - para.In = p[1] + switch p[1] { + case "query": + fallthrough + case "header": + fallthrough + case "path": + fallthrough + case "formData": + fallthrough + case "body": + para.In = p[1] + default: + fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param location: %s, Possible values are `query`, `header`, `path`, `formData` or `body`.\n", controllerName, funcName, p[1]) + } + pp := strings.Split(p[2], ".") typ := pp[len(pp)-1] if len(pp) >= 2 { From 2f85185bcc1d5d6eeb86224a42138d5734fc4b37 Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 21:03:27 +0800 Subject: [PATCH 4/6] Print warnning only if param location is wrong --- g_docs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g_docs.go b/g_docs.go index 0233650..dc7be88 100644 --- a/g_docs.go +++ b/g_docs.go @@ -419,11 +419,11 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat case "formData": fallthrough case "body": - para.In = p[1] + break default: fmt.Fprintf(os.Stderr, "[%s.%s] Unknow param location: %s, Possible values are `query`, `header`, `path`, `formData` or `body`.\n", controllerName, funcName, p[1]) } - + para.In = p[1] pp := strings.Split(p[2], ".") typ := pp[len(pp)-1] if len(pp) >= 2 { From 3ccffe087e7dbca0d7bf46801f7e29696fd4f069 Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 21:30:57 +0800 Subject: [PATCH 5/6] update swagger array items define --- g_docs.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/g_docs.go b/g_docs.go index dc7be88..3199e13 100644 --- a/g_docs.go +++ b/g_docs.go @@ -603,17 +603,17 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp // add type slice if isSlice { mp.Type = "array" - mp.Properties = make(map[string]swagger.Propertie) if isBasicType(realType) { typeFormat := strings.Split(sType, ":") - mp.Properties["items"] = swagger.Propertie{ + mp.Items = []swagger.Propertie{{ Type: typeFormat[0], Format: typeFormat[1], - } + }} + } else { - mp.Properties["items"] = swagger.Propertie{ + mp.Items = []swagger.Propertie{{ Ref: "#/definitions/" + realType, - } + }} } } else { if isBasicType(realType) { From 1e247452fff6c25948882e4f4ce9c62c4460b62c Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 18 Aug 2016 22:29:38 +0800 Subject: [PATCH 6/6] update swagger --- g_docs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/g_docs.go b/g_docs.go index 3199e13..5a0a047 100644 --- a/g_docs.go +++ b/g_docs.go @@ -605,15 +605,15 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp mp.Type = "array" if isBasicType(realType) { typeFormat := strings.Split(sType, ":") - mp.Items = []swagger.Propertie{{ + mp.Items = &swagger.Propertie{ Type: typeFormat[0], Format: typeFormat[1], - }} + } } else { - mp.Items = []swagger.Propertie{{ + mp.Items = &swagger.Propertie{ Ref: "#/definitions/" + realType, - }} + } } } else { if isBasicType(realType) {