diff --git a/cmd/commands/generate/generate.go b/cmd/commands/generate/generate.go index 1936b3c..8d36039 100644 --- a/cmd/commands/generate/generate.go +++ b/cmd/commands/generate/generate.go @@ -99,12 +99,30 @@ func GenerateCode(cmd *commands.Command, args []string) int { tags = []string{} } + // get apis value + apisIndex := -1 + for i, arg := range args { + if arg == "--apis" && i+1 < len(args) { + apisIndex = i + 1 + break + } + } + var apis []string + if apisIndex != -1 { + apis = strings.Split(args[apisIndex], ",") + for i, str := range apis { + apis[i] = "/" + strings.TrimSpace(str) + } + } else { + apis = []string{} + } + gcmd := args[0] switch gcmd { case "scaffold": scaffold(cmd, args, currpath) case "docs": - swaggergen.GenerateDocs(currpath, tags) + swaggergen.GenerateDocs(currpath, tags, apis) case "appcode": appCode(cmd, args, currpath) case "migration": diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index d0bd672..866687d 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -157,7 +157,7 @@ func parsePackageFromDir(path string) error { } // GenerateDocs generates documentations for a given path. -func GenerateDocs(curpath string, tags []string) { +func GenerateDocs(curpath string, tags []string, apis []string) { pkgspath := curpath workspace := os.Getenv("BeeWorkspace") if workspace != "" { @@ -302,6 +302,21 @@ func GenerateDocs(curpath string, tags []string) { } } + // fileter the controllerList by apis + if len(apis)>0 { + for key, controllerValue := range controllerList { + apiMap := make(map[string]*swagger.Item) + for _, api := range apis{ + if item, ok := controllerValue[api]; ok { + apiMap[api] = item + } else { + beeLogger.Log.Warnf("api %s not found in controller %s", api, key) + } + } + controllerList[key] = apiMap + } + } + for _, d := range f.Decls { switch specDecl := d.(type) { case *ast.FuncDecl: