From c76d4d1451d1417694e215c5aafc0fbe4a851ea6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 22:55:12 +0800 Subject: [PATCH 01/13] add publish target --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 7259aa6..d626070 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +VERSION = $(shell grep 'const version' cmd/commands/version/version.go | sed -E 's/.*"(.+)"$$/v\1/') + .PHONY: all test clean build install GOFLAGS ?= $(GOFLAGS:) @@ -18,3 +20,10 @@ bench: install clean: go clean $(GOFLAGS) -i ./... + +publish: + mkdir -p bin/$(VERSION) + cd bin/$(VERSION) + xgo -v -x --targets="windows/*,darwin/*,linux/386,linux/amd64,linux/arm-5,linux/arm64" -out bee_$(VERSION) github.com/beego/bee + cd .. + ghr -u beego -r bee $(VERSION) $(VERSION) \ No newline at end of file From a117a48d7ba61eac3da4eca440e8cf08c65c43ab Mon Sep 17 00:00:00 2001 From: eyalpost Date: Wed, 26 Apr 2017 00:10:03 +0300 Subject: [PATCH 02/13] add support for controller methods with paramaters - allow automatic mapping of type from method params - generate swagger for parameters not covered by comment annotations --- generate/swaggergen/g_docs.go | 158 ++++++++++++++++++++++++++-------- 1 file changed, 124 insertions(+), 34 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index a9f1c0a..3e8cca0 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -362,11 +362,11 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { pkgRealpath = wg } else { wgopath := gopaths - for _, wg := range wgopath { - wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) - if utils.FileExists(wg) { - pkgRealpath = wg - break + for _, wg := range wgopath { + wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) + if utils.FileExists(wg) { + pkgRealpath = wg + break } } } @@ -395,7 +395,7 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { if specDecl.Recv != nil && len(specDecl.Recv.List) > 0 { if t, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr); ok { // Parse controller method - parserComments(specDecl.Doc, specDecl.Name.String(), fmt.Sprint(t.X), pkgpath) + parserComments(specDecl, fmt.Sprint(t.X), pkgpath) } } case *ast.GenDecl: @@ -448,12 +448,16 @@ func peekNextSplitString(ss string) (s string, spacePos int) { } // parse the func comments -func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpath string) error { +func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { var routerPath string var HTTPMethod string opts := swagger.Operation{ Responses: make(map[string]swagger.Response), } + funcName := f.Name.String() + comments := f.Doc + funcParamMap := buildParamMap(f.Type.Params) + //TODO: resultMap := buildParamMap(f.Type.Results) if comments != nil && comments.List != nil { for _, c := range comments.List { t := strings.TrimSpace(strings.TrimLeft(c.Text, "//")) @@ -526,7 +530,17 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat if len(p) < 4 { beeLogger.Log.Fatal(controllerName + "_" + funcName + "'s comments @Param should have at least 4 params") } - para.Name = p[0] + paramNames := strings.SplitN(p[0], "=>", 2) + para.Name = paramNames[0] + funcParamName := para.Name + if len(paramNames) > 1 { + funcParamName = paramNames[1] + } + paramType, ok := funcParamMap[funcParamName] + if ok { + delete(funcParamMap, funcParamName) + } + switch p[1] { case "query": fallthrough @@ -555,33 +569,10 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat modelsList[pkgpath+controllerName][typ] = mod appendModels(pkgpath, controllerName, realTypes) } else { - isArray := false - paraType := "" - paraFormat := "" - if strings.HasPrefix(typ, "[]") { - typ = typ[2:] - isArray = true - } - if typ == "string" || typ == "number" || typ == "integer" || typ == "boolean" || - typ == "array" || typ == "file" { - paraType = typ - } else if sType, ok := basicTypes[typ]; ok { - typeFormat := strings.Split(sType, ":") - paraType = typeFormat[0] - paraFormat = typeFormat[1] - } else { - beeLogger.Log.Warnf("[%s.%s] Unknown 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 typ == "auto" { + typ = paramType } + setParamType(¶, typ, pkgpath, controllerName) } switch len(p) { case 5: @@ -636,7 +627,21 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat } } } + if routerPath != "" { + //Go over function parameters which were not mapped and create swagger params for them + for name, typ := range funcParamMap { + para := swagger.Parameter{} + para.Name = name + setParamType(¶, typ, pkgpath, controllerName) + if paramInPath(name, routerPath) { + para.In = "path" + } else { + para.In = "query" + } + opts.Parameters = append(opts.Parameters, para) + } + var item *swagger.Item if itemList, ok := controllerList[pkgpath+controllerName]; ok { if it, ok := itemList[routerPath]; !ok { @@ -669,6 +674,91 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat return nil } +func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName string) { + isArray := false + paraType := "" + paraFormat := "" + + if strings.HasPrefix(typ, "[]") { + typ = typ[2:] + isArray = true + } + if typ == "string" || typ == "number" || typ == "integer" || typ == "boolean" || + typ == "array" || typ == "file" { + paraType = typ + } else if sType, ok := basicTypes[typ]; ok { + typeFormat := strings.Split(sType, ":") + paraType = typeFormat[0] + paraFormat = typeFormat[1] + } else { + m, mod, realTypes := getModel(typ) + para.Schema = &swagger.Schema{ + Ref: "#/definitions/" + m, + } + if _, ok := modelsList[pkgpath+controllerName]; !ok { + modelsList[pkgpath+controllerName] = make(map[string]swagger.Schema) + } + modelsList[pkgpath+controllerName][typ] = mod + appendModels(pkgpath, controllerName, realTypes) + } + if isArray { + para.Type = "array" + para.Items = &swagger.ParameterItems{ + Type: paraType, + Format: paraFormat, + } + } else { + para.Type = paraType + para.Format = paraFormat + } + +} + +func paramInPath(name, route string) bool { + return strings.HasSuffix(route, ":"+name) || + strings.Contains(route, ":"+name+"/") +} + +func getFunctionParamType(t ast.Expr) string { + switch paramType := t.(type) { + case *ast.Ident: + return paramType.Name + // case *ast.Ellipsis: + // result := getFunctionParamType(paramType.Elt) + // result.array = true + // return result + case *ast.ArrayType: + return "[]" + getFunctionParamType(paramType.Elt) + case *ast.StarExpr: + return getFunctionParamType(paramType.X) + case *ast.SelectorExpr: + return getFunctionParamType(paramType.X) + "." + paramType.Sel.Name + default: + return "" + + } +} + +func buildParamMap(list *ast.FieldList) map[string]string { + i := 0 + result := map[string]string{} + if list != nil { + funcParams := list.List + for _, fparam := range funcParams { + param := getFunctionParamType(fparam.Type) + var paramName string + if len(fparam.Names) > 0 { + paramName = fparam.Names[0].Name + } else { + paramName = fmt.Sprint(i) + i++ + } + result[paramName] = param + } + } + return result +} + // analisys params return []string // @Param query form string true "The email for login" // [query form string true "The email for login"] From 823dca76d5fe12aa915b0007667ccabdafa02272 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 28 Apr 2017 20:36:44 +0800 Subject: [PATCH 03/13] add gofmt check for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 32a2f34..4cbff6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ install: - go get -u honnef.co/go/tools/cmd/unused - go get -u github.com/mdempsky/unconvert script: + - find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s - go vet $(go list ./... | grep -v /vendor/) - structcheck $(go list ./... | grep -v /vendor/) - gosimple -ignore "$(cat gosimple.ignore)" $(go list ./... | grep -v /vendor/) From e1f3353511ed4ded4c89ae7d738b1712552e170b Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 28 Apr 2017 22:53:38 +0800 Subject: [PATCH 04/13] add ineffassign check --- .travis.yml | 2 ++ cmd/commands/pack/pack.go | 2 +- generate/g_appcode.go | 6 ++---- generate/g_hproseappcode.go | 2 +- generate/swaggergen/g_docs.go | 7 ++----- logger/colors/colorwriter_windows.go | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4cbff6e..b0e346b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - go get -u honnef.co/go/tools/cmd/staticcheck - go get -u honnef.co/go/tools/cmd/unused - go get -u github.com/mdempsky/unconvert + - go get -u github.com/gordonklaus/ineffassign script: - find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s - go vet $(go list ./... | grep -v /vendor/) @@ -18,3 +19,4 @@ script: - staticcheck $(go list ./... | grep -v /vendor/) - unused $(go list ./... | grep -v /vendor/) - unconvert $(go list ./... | grep -v /vendor/) + - ineffassign . diff --git a/cmd/commands/pack/pack.go b/cmd/commands/pack/pack.go index ee7eced..becddcc 100644 --- a/cmd/commands/pack/pack.go +++ b/cmd/commands/pack/pack.go @@ -417,7 +417,7 @@ func packDirectory(output io.Writer, excludePrefix []string, excludeSuffix []str func packApp(cmd *commands.Command, args []string) int { output := cmd.Out() curPath, _ := os.Getwd() - thePath := "" + var thePath string nArgs := []string{} has := false diff --git a/generate/g_appcode.go b/generate/g_appcode.go index fd6a3ed..f575568 100644 --- a/generate/g_appcode.go +++ b/generate/g_appcode.go @@ -503,9 +503,7 @@ func (mysqlDB *MysqlDB) GetColumns(db *sql.DB, table *Table, blackList map[strin // GetGoDataType maps an SQL data type to Golang data type func (*MysqlDB) GetGoDataType(sqlType string) (string, error) { - var typeMapping = map[string]string{} - typeMapping = typeMappingMysql - if v, ok := typeMapping[sqlType]; ok { + if v, ok := typeMappingMysql[sqlType]; ok { return v, nil } return "", fmt.Errorf("data type '%s' not found", sqlType) @@ -766,7 +764,7 @@ func writeModelFiles(tables []*Table, mPath string, selectedTables map[string]bo continue } } - template := "" + var template string if tb.Pk == "" { template = StructModelTPL } else { diff --git a/generate/g_hproseappcode.go b/generate/g_hproseappcode.go index f73d6ff..f6d352d 100644 --- a/generate/g_hproseappcode.go +++ b/generate/g_hproseappcode.go @@ -369,7 +369,7 @@ func writeHproseModelFiles(tables []*Table, mPath string, selectedTables map[str continue } } - template := "" + var template string if tb.Pk == "" { template = HproseStructModelTPL } else { diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index a9f1c0a..36dcec4 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -216,7 +216,7 @@ func GenerateDocs(curpath string) { for _, p := range params { switch pp := p.(type) { case *ast.CallExpr: - controllerName := "" + var controllerName string if selname := pp.Fun.(*ast.SelectorExpr).Sel.String(); selname == "NSNamespace" { s, params := analyseNewNamespace(pp) for _, sp := range params { @@ -298,12 +298,10 @@ func analyseNSInclude(baseurl string, ce *ast.CallExpr) string { } if apis, ok := controllerList[cname]; ok { for rt, item := range apis { - tag := "" + tag := cname if baseurl != "" { rt = baseurl + rt tag = strings.Trim(baseurl, "/") - } else { - tag = cname } if item.Get != nil { item.Get.Tags = []string{tag} @@ -749,7 +747,6 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string if st.Fields.List != nil { m.Properties = make(map[string]swagger.Propertie) for _, field := range st.Fields.List { - realType := "" isSlice, realType, sType := typeAnalyser(field) if (isSlice && isBasicType(realType)) || sType == "object" { if len(strings.Split(realType, " ")) > 1 { diff --git a/logger/colors/colorwriter_windows.go b/logger/colors/colorwriter_windows.go index d4c567a..67acb93 100644 --- a/logger/colors/colorwriter_windows.go +++ b/logger/colors/colorwriter_windows.go @@ -360,7 +360,7 @@ func isParameterChar(b byte) bool { } func (cw *colorWriter) Write(p []byte) (int, error) { - r, nw, first, last := 0, 0, 0, 0 + var r, nw, first, last int if cw.mode != DiscardNonColorEscSeq { cw.state = outsideCsiCode cw.resetBuffer() From 65aec741fb6838c684ed096fd2b5a20db2b65153 Mon Sep 17 00:00:00 2001 From: eyalpost Date: Fri, 28 Apr 2017 18:45:26 +0300 Subject: [PATCH 05/13] go fmt --- generate/swaggergen/g_docs.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 3e8cca0..b99f900 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -362,11 +362,11 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { pkgRealpath = wg } else { wgopath := gopaths - for _, wg := range wgopath { - wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) - if utils.FileExists(wg) { - pkgRealpath = wg - break + for _, wg := range wgopath { + wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) + if utils.FileExists(wg) { + pkgRealpath = wg + break } } } From 3f63cd706f1c4ba58116bcc6ce159dc6c92b5037 Mon Sep 17 00:00:00 2001 From: guoshaowei Date: Fri, 5 May 2017 10:59:45 +0800 Subject: [PATCH 06/13] fix gen doc slice type bug --- generate/swaggergen/g_docs.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 36dcec4..268a249 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -762,7 +762,7 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string mp := swagger.Propertie{} if isSlice { mp.Type = "array" - if isBasicType(realType) { + if isBasicType(strings.Replace(realType, "[]", "", -1)) { typeFormat := strings.Split(sType, ":") mp.Items = &swagger.Propertie{ Type: typeFormat[0], @@ -864,6 +864,11 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { if arr, ok := f.Type.(*ast.ArrayType); ok { + //arr.Len nil for slice types + if arr.Len == nil { + return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] + } + if isBasicType(fmt.Sprint(arr.Elt)) { return false, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] } From 50ae47c61f2195cfb0c2d4cd9fe8f3bbc6358b9b Mon Sep 17 00:00:00 2001 From: guoshaowei Date: Fri, 5 May 2017 11:31:03 +0800 Subject: [PATCH 07/13] fix gen doc slice type bug --- generate/swaggergen/g_docs.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 268a249..635ef06 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -864,13 +864,8 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { if arr, ok := f.Type.(*ast.ArrayType); ok { - //arr.Len nil for slice types - if arr.Len == nil { - return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] - } - if isBasicType(fmt.Sprint(arr.Elt)) { - return false, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] + return true, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)] } if mp, ok := arr.Elt.(*ast.MapType); ok { return false, fmt.Sprintf("map[%v][%v]", mp.Key, mp.Value), "object" From 4ef471170e488f93cd52eaf29e82eb0913f55162 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Mon, 8 May 2017 08:38:06 +0800 Subject: [PATCH 08/13] Fixed an error in the basicType of pointer when the swagger document was automatically generated --- generate/swaggergen/g_docs.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 635ef06..3df90e8 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -877,6 +877,10 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { } switch t := f.Type.(type) { case *ast.StarExpr: + basicType := fmt.Sprint(t.X) + if k, ok := basicTypes[basicType]; ok { + return false, basicType, k + } return false, fmt.Sprint(t.X), "object" case *ast.MapType: val := fmt.Sprintf("%v", t.Value) From 49d791502a4969287b1bfe44eb3d2702743040a5 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Mon, 8 May 2017 08:41:12 +0800 Subject: [PATCH 09/13] Fixed an error in the basicType of pointer when the swagger document was automatically generated --- 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 3df90e8..a23a677 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -881,7 +881,7 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { if k, ok := basicTypes[basicType]; ok { return false, basicType, k } - return false, fmt.Sprint(t.X), "object" + return false, basicType, "object" case *ast.MapType: val := fmt.Sprintf("%v", t.Value) if isBasicType(val) { From fef25c2c5fa828e5ac9895693f4f03dcf5e235a2 Mon Sep 17 00:00:00 2001 From: franzwilhelm Date: Sun, 14 May 2017 00:35:18 +0200 Subject: [PATCH 10/13] add complete swagger 3.0 security support for oauth2, apiKey and basic fix len(p) handling, add support for global security update swagger.go in vendor, fix redundant break --- generate/swaggergen/g_docs.go | 71 ++++++++++++++++++- .../astaxie/beego/swagger/swagger.go | 49 ++++++------- 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index a9f1c0a..cff307c 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -184,11 +184,62 @@ func GenerateDocs(curpath string) { rootapi.Schemes = strings.Split(strings.TrimSpace(s[len("@Schemes"):]), ",") } else if strings.HasPrefix(s, "@Host") { rootapi.Host = strings.TrimSpace(s[len("@Host"):]) + } else if strings.HasPrefix(s, "@SecurityDefinition") { + if len(rootapi.SecurityDefinitions) == 0 { + rootapi.SecurityDefinitions = make(map[string]swagger.Security) + } + var out swagger.Security + p := getparams(strings.TrimSpace(s[len("@SecurityDefinition"):])) + if len(p) < 2 { + beeLogger.Log.Fatalf("Not enough params for security: %d\n", len(p)) + } + out.Type = p[1] + switch out.Type { + case "oauth2": + if len(p) < 6 { + beeLogger.Log.Fatalf("Not enough params for oauth2: %d\n", len(p)) + } + if !(p[3] == "implicit" || p[3] == "password" || p[3] == "application" || p[3] == "accessCode") { + beeLogger.Log.Fatalf("Unknown flow type: %s. Possible values are `implicit`, `password`, `application` or `accessCode`.\n", p[1]) + } + out.AuthorizationURL = p[2] + out.Flow = p[3] + if len(p)%2 != 0 { + out.Description = strings.Trim(p[len(p)-1], `" `) + } + out.Scopes = make(map[string]string) + for i := 4; i < len(p)-1; i += 2 { + out.Scopes[p[i]] = strings.Trim(p[i+1], `" `) + } + case "apiKey": + if len(p) < 4 { + beeLogger.Log.Fatalf("Not enough params for apiKey: %d\n", len(p)) + } + if !(p[3] == "header" || p[3] == "query") { + beeLogger.Log.Fatalf("Unknown in type: %s. Possible values are `query` or `header`.\n", p[4]) + } + out.Name = p[2] + out.In = p[3] + if len(p) > 4 { + out.Description = strings.Trim(p[4], `" `) + } + case "basic": + if len(p) > 2 { + out.Description = strings.Trim(p[2], `" `) + } + default: + beeLogger.Log.Fatalf("Unknown security type: %s. Possible values are `oauth2`, `apiKey` or `basic`.\n", p[1]) + } + rootapi.SecurityDefinitions[p[0]] = out + } else if strings.HasPrefix(s, "@Security") { + if len(rootapi.Security) == 0 { + rootapi.Security = make([]map[string][]string, 0) + } + rootapi.Security = append(rootapi.Security, getSecurity(s)) } } } } - // Analyse controller package for _, im := range f.Imports { localName := "" @@ -633,6 +684,11 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat opts.Produces = append(opts.Produces, ahtml) } } + } else if strings.HasPrefix(t, "@Security") { + if len(opts.Security) == 0 { + opts.Security = make([]map[string][]string, 0) + } + opts.Security = append(opts.Security, getSecurity(t)) } } } @@ -920,6 +976,19 @@ func appendModels(pkgpath, controllerName string, realTypes []string) { } } +func getSecurity(t string) (security map[string][]string) { + security = make(map[string][]string) + p := getparams(strings.TrimSpace(t[len("@Security"):])) + if len(p) == 0 { + beeLogger.Log.Fatalf("No params for security specified\n") + } + security[p[0]] = make([]string, 0) + for i := 1; i < len(p); i++ { + security[p[0]] = append(security[p[0]], p[i]) + } + return +} + func urlReplace(src string) string { pt := strings.Split(src, "/") for i, p := range pt { diff --git a/vendor/github.com/astaxie/beego/swagger/swagger.go b/vendor/github.com/astaxie/beego/swagger/swagger.go index e0ac5cf..035d5a4 100644 --- a/vendor/github.com/astaxie/beego/swagger/swagger.go +++ b/vendor/github.com/astaxie/beego/swagger/swagger.go @@ -22,19 +22,19 @@ package swagger // Swagger list the resource type Swagger struct { - SwaggerVersion string `json:"swagger,omitempty" yaml:"swagger,omitempty"` - Infos Information `json:"info" yaml:"info"` - Host string `json:"host,omitempty" yaml:"host,omitempty"` - BasePath string `json:"basePath,omitempty" yaml:"basePath,omitempty"` - Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` - Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` - Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` - Paths map[string]*Item `json:"paths" yaml:"paths"` - Definitions map[string]Schema `json:"definitions,omitempty" yaml:"definitions,omitempty"` - SecurityDefinitions map[string]Security `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"` - Security map[string][]string `json:"security,omitempty" yaml:"security,omitempty"` - Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"` - ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"` + SwaggerVersion string `json:"swagger,omitempty" yaml:"swagger,omitempty"` + Infos Information `json:"info" yaml:"info"` + Host string `json:"host,omitempty" yaml:"host,omitempty"` + BasePath string `json:"basePath,omitempty" yaml:"basePath,omitempty"` + Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` + Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` + Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` + Paths map[string]*Item `json:"paths" yaml:"paths"` + Definitions map[string]Schema `json:"definitions,omitempty" yaml:"definitions,omitempty"` + SecurityDefinitions map[string]Security `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"` + Security []map[string][]string `json:"security,omitempty" yaml:"security,omitempty"` + Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"` } // Information Provides metadata about the API. The metadata can be used by the clients if needed. @@ -75,16 +75,17 @@ type Item struct { // Operation Describes a single API operation on a path. type Operation struct { - Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` - Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` - Description string `json:"description,omitempty" yaml:"description,omitempty"` - OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"` - Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` - Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` - Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` - Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"` - Responses map[string]Response `json:"responses,omitempty" yaml:"responses,omitempty"` - Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` + Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` + Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` + Description string `json:"description,omitempty" yaml:"description,omitempty"` + OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"` + Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` + Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` + Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` + Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"` + Responses map[string]Response `json:"responses,omitempty" yaml:"responses,omitempty"` + Security []map[string][]string `json:"security,omitempty" yaml:"security,omitempty"` + Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` } // Parameter Describes a single operation parameter. @@ -100,7 +101,7 @@ type Parameter struct { Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` } -// A limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body". +// ParameterItems A limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body". // http://swagger.io/specification/#itemsObject type ParameterItems struct { Type string `json:"type,omitempty" yaml:"type,omitempty"` From e8c0f528a66ad635f0c2fdf18688cddda9548255 Mon Sep 17 00:00:00 2001 From: franzwilhelm Date: Mon, 15 May 2017 00:32:45 +0200 Subject: [PATCH 11/13] add ignore for staticcheck --- .travis.yml | 2 +- gosimple.ignore | 1 + staticcheck.ignore | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 staticcheck.ignore diff --git a/.travis.yml b/.travis.yml index 32a2f34..5acc9f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,6 @@ script: - go vet $(go list ./... | grep -v /vendor/) - structcheck $(go list ./... | grep -v /vendor/) - gosimple -ignore "$(cat gosimple.ignore)" $(go list ./... | grep -v /vendor/) - - staticcheck $(go list ./... | grep -v /vendor/) + - staticcheck -ignore "$(cat staticcheck.ignore)" $(go list ./... | grep -v /vendor/) - unused $(go list ./... | grep -v /vendor/) - unconvert $(go list ./... | grep -v /vendor/) diff --git a/gosimple.ignore b/gosimple.ignore index 68e88ac..4619dba 100644 --- a/gosimple.ignore +++ b/gosimple.ignore @@ -1,2 +1,3 @@ github.com/beego/bee/cmd/commands/run/*.go:S1024 github.com/beego/bee/cmd/commands/dlv/*.go:S1024 +github.com/beego/bee/utils/*.go:S1026 diff --git a/staticcheck.ignore b/staticcheck.ignore new file mode 100644 index 0000000..70d9589 --- /dev/null +++ b/staticcheck.ignore @@ -0,0 +1 @@ +github.com/beego/bee/generate/swaggergen/*.go:SA1024 From 0d0e583346dac84765d9ee9d68789ce0009a9322 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 18 May 2017 22:58:13 +0800 Subject: [PATCH 12/13] v1.8.4 --- cmd/commands/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index b318c8e..563b6dd 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -57,7 +57,7 @@ Prints the current Bee, Beego and Go version alongside the platform information. } var outputFormat string -const version = "1.8.3" +const version = "1.8.4" func init() { fs := flag.NewFlagSet("version", flag.ContinueOnError) From 0000e7d7c9d6a9844b0f520929485239c7ace3a3 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 19 May 2017 09:41:47 +0800 Subject: [PATCH 13/13] gosimple --- 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 c008f03..ae8f297 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -822,7 +822,7 @@ func getparams(str string) []string { var start bool var r []string var quoted int8 - for _, c := range []rune(str) { + for _, c := range str { if unicode.IsSpace(c) && quoted == 0 { if !start { continue