mirror of
https://github.com/casbin/bee.git
synced 2025-07-08 00:50:25 +08:00
feat: support generating Swagger docs by api (#6)
This commit is contained in:
@ -99,12 +99,30 @@ func GenerateCode(cmd *commands.Command, args []string) int {
|
|||||||
tags = []string{}
|
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]
|
gcmd := args[0]
|
||||||
switch gcmd {
|
switch gcmd {
|
||||||
case "scaffold":
|
case "scaffold":
|
||||||
scaffold(cmd, args, currpath)
|
scaffold(cmd, args, currpath)
|
||||||
case "docs":
|
case "docs":
|
||||||
swaggergen.GenerateDocs(currpath, tags)
|
swaggergen.GenerateDocs(currpath, tags, apis)
|
||||||
case "appcode":
|
case "appcode":
|
||||||
appCode(cmd, args, currpath)
|
appCode(cmd, args, currpath)
|
||||||
case "migration":
|
case "migration":
|
||||||
|
@ -157,7 +157,7 @@ func parsePackageFromDir(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerateDocs generates documentations for a given path.
|
// GenerateDocs generates documentations for a given path.
|
||||||
func GenerateDocs(curpath string, tags []string) {
|
func GenerateDocs(curpath string, tags []string, apis []string) {
|
||||||
pkgspath := curpath
|
pkgspath := curpath
|
||||||
workspace := os.Getenv("BeeWorkspace")
|
workspace := os.Getenv("BeeWorkspace")
|
||||||
if workspace != "" {
|
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 {
|
for _, d := range f.Decls {
|
||||||
switch specDecl := d.(type) {
|
switch specDecl := d.(type) {
|
||||||
case *ast.FuncDecl:
|
case *ast.FuncDecl:
|
||||||
|
Reference in New Issue
Block a user