mirror of
https://github.com/beego/bee.git
synced 2024-11-22 20:20:55 +00:00
Merge pull request #131 from pjoe/update_to_match_beego_develop
Update generate docs to match changes in beego develop branch
This commit is contained in:
commit
d70592fd14
54
g_docs.go
54
g_docs.go
@ -52,7 +52,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var rootapi swagger.ResourceListing
|
var rootapi swagger.ResourceListing
|
||||||
var apilist map[string]*swagger.ApiDeclaration
|
var apilist map[string]*swagger.APIDeclaration
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if beego.EnableDocs {
|
if beego.EnableDocs {
|
||||||
@ -64,14 +64,14 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
}
|
}
|
||||||
beego.GlobalDocApi["Root"] = rootapi
|
beego.GlobalDocAPI["Root"] = rootapi
|
||||||
for k, v := range apilist {
|
for k, v := range apilist {
|
||||||
for i, a := range v.Apis {
|
for i, a := range v.APIs {
|
||||||
a.Path = urlReplace(k + a.Path)
|
a.Path = urlReplace(k + a.Path)
|
||||||
v.Apis[i] = a
|
v.APIs[i] = a
|
||||||
}
|
}
|
||||||
v.BasePath = BasePath
|
v.BasePath = BasePath
|
||||||
beego.GlobalDocApi[strings.Trim(k, "/")] = v
|
beego.GlobalDocAPI[strings.Trim(k, "/")] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,8 +102,8 @@ const (
|
|||||||
var pkgCache map[string]bool //pkg:controller:function:comments comments: key:value
|
var pkgCache map[string]bool //pkg:controller:function:comments comments: key:value
|
||||||
var controllerComments map[string]string
|
var controllerComments map[string]string
|
||||||
var importlist map[string]string
|
var importlist map[string]string
|
||||||
var apilist map[string]*swagger.ApiDeclaration
|
var apilist map[string]*swagger.APIDeclaration
|
||||||
var controllerList map[string][]swagger.Api
|
var controllerList map[string][]swagger.API
|
||||||
var modelsList map[string]map[string]swagger.Model
|
var modelsList map[string]map[string]swagger.Model
|
||||||
var rootapi swagger.ResourceListing
|
var rootapi swagger.ResourceListing
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ func init() {
|
|||||||
pkgCache = make(map[string]bool)
|
pkgCache = make(map[string]bool)
|
||||||
controllerComments = make(map[string]string)
|
controllerComments = make(map[string]string)
|
||||||
importlist = make(map[string]string)
|
importlist = make(map[string]string)
|
||||||
apilist = make(map[string]*swagger.ApiDeclaration)
|
apilist = make(map[string]*swagger.APIDeclaration)
|
||||||
controllerList = make(map[string][]swagger.Api)
|
controllerList = make(map[string][]swagger.API)
|
||||||
modelsList = make(map[string]map[string]swagger.Model)
|
modelsList = make(map[string]map[string]swagger.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,19 +133,19 @@ func generateDocs(curpath string) {
|
|||||||
for _, c := range f.Comments {
|
for _, c := range f.Comments {
|
||||||
for _, s := range strings.Split(c.Text(), "\n") {
|
for _, s := range strings.Split(c.Text(), "\n") {
|
||||||
if strings.HasPrefix(s, "@APIVersion") {
|
if strings.HasPrefix(s, "@APIVersion") {
|
||||||
rootapi.ApiVersion = strings.TrimSpace(s[len("@APIVersion"):])
|
rootapi.APIVersion = strings.TrimSpace(s[len("@APIVersion"):])
|
||||||
} else if strings.HasPrefix(s, "@Title") {
|
} else if strings.HasPrefix(s, "@Title") {
|
||||||
rootapi.Infos.Title = strings.TrimSpace(s[len("@Title"):])
|
rootapi.Infos.Title = strings.TrimSpace(s[len("@Title"):])
|
||||||
} else if strings.HasPrefix(s, "@Description") {
|
} else if strings.HasPrefix(s, "@Description") {
|
||||||
rootapi.Infos.Description = strings.TrimSpace(s[len("@Description"):])
|
rootapi.Infos.Description = strings.TrimSpace(s[len("@Description"):])
|
||||||
} else if strings.HasPrefix(s, "@TermsOfServiceUrl") {
|
} else if strings.HasPrefix(s, "@TermsOfServiceUrl") {
|
||||||
rootapi.Infos.TermsOfServiceUrl = strings.TrimSpace(s[len("@TermsOfServiceUrl"):])
|
rootapi.Infos.TermsOfServiceURL = strings.TrimSpace(s[len("@TermsOfServiceUrl"):])
|
||||||
} else if strings.HasPrefix(s, "@Contact") {
|
} else if strings.HasPrefix(s, "@Contact") {
|
||||||
rootapi.Infos.Contact = strings.TrimSpace(s[len("@Contact"):])
|
rootapi.Infos.Contact = strings.TrimSpace(s[len("@Contact"):])
|
||||||
} else if strings.HasPrefix(s, "@License") {
|
} else if strings.HasPrefix(s, "@License") {
|
||||||
rootapi.Infos.License = strings.TrimSpace(s[len("@License"):])
|
rootapi.Infos.License = strings.TrimSpace(s[len("@License"):])
|
||||||
} else if strings.HasPrefix(s, "@LicenseUrl") {
|
} else if strings.HasPrefix(s, "@LicenseUrl") {
|
||||||
rootapi.Infos.LicenseUrl = strings.TrimSpace(s[len("@LicenseUrl"):])
|
rootapi.Infos.LicenseURL = strings.TrimSpace(s[len("@LicenseUrl"):])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ func generateDocs(curpath string) {
|
|||||||
case *ast.CallExpr:
|
case *ast.CallExpr:
|
||||||
if selname := pp.Fun.(*ast.SelectorExpr).Sel.String(); selname == "NSNamespace" {
|
if selname := pp.Fun.(*ast.SelectorExpr).Sel.String(); selname == "NSNamespace" {
|
||||||
s, params := analisysNewNamespace(pp)
|
s, params := analisysNewNamespace(pp)
|
||||||
subapi := swagger.ApiRef{Path: s}
|
subapi := swagger.APIRef{Path: s}
|
||||||
controllerName := ""
|
controllerName := ""
|
||||||
for _, sp := range params {
|
for _, sp := range params {
|
||||||
switch pp := sp.(type) {
|
switch pp := sp.(type) {
|
||||||
@ -185,7 +185,7 @@ func generateDocs(curpath string) {
|
|||||||
if v, ok := controllerComments[controllerName]; ok {
|
if v, ok := controllerComments[controllerName]; ok {
|
||||||
subapi.Description = v
|
subapi.Description = v
|
||||||
}
|
}
|
||||||
rootapi.Apis = append(rootapi.Apis, subapi)
|
rootapi.APIs = append(rootapi.APIs, subapi)
|
||||||
} else if selname == "NSInclude" {
|
} else if selname == "NSInclude" {
|
||||||
analisysNSInclude(f, pp)
|
analisysNSInclude(f, pp)
|
||||||
}
|
}
|
||||||
@ -233,12 +233,12 @@ func analisysNewNamespace(ce *ast.CallExpr) (first string, others []ast.Expr) {
|
|||||||
|
|
||||||
func analisysNSInclude(baseurl string, ce *ast.CallExpr) string {
|
func analisysNSInclude(baseurl string, ce *ast.CallExpr) string {
|
||||||
cname := ""
|
cname := ""
|
||||||
a := &swagger.ApiDeclaration{}
|
a := &swagger.APIDeclaration{}
|
||||||
a.ApiVersion = rootapi.ApiVersion
|
a.APIVersion = rootapi.APIVersion
|
||||||
a.SwaggerVersion = swagger.SwaggerVersion
|
a.SwaggerVersion = swagger.SwaggerVersion
|
||||||
a.ResourcePath = baseurl
|
a.ResourcePath = baseurl
|
||||||
a.Produces = []string{"application/json", "application/xml", "text/plain", "text/html"}
|
a.Produces = []string{"application/json", "application/xml", "text/plain", "text/html"}
|
||||||
a.Apis = make([]swagger.Api, 0)
|
a.APIs = make([]swagger.API, 0)
|
||||||
a.Models = make(map[string]swagger.Model)
|
a.Models = make(map[string]swagger.Model)
|
||||||
for _, p := range ce.Args {
|
for _, p := range ce.Args {
|
||||||
x := p.(*ast.UnaryExpr).X.(*ast.CompositeLit).Type.(*ast.SelectorExpr)
|
x := p.(*ast.UnaryExpr).X.(*ast.CompositeLit).Type.(*ast.SelectorExpr)
|
||||||
@ -246,15 +246,15 @@ func analisysNSInclude(baseurl string, ce *ast.CallExpr) string {
|
|||||||
cname = v + x.Sel.Name
|
cname = v + x.Sel.Name
|
||||||
}
|
}
|
||||||
if apis, ok := controllerList[cname]; ok {
|
if apis, ok := controllerList[cname]; ok {
|
||||||
if len(a.Apis) > 0 {
|
if len(a.APIs) > 0 {
|
||||||
a.Apis = append(a.Apis, apis...)
|
a.APIs = append(a.APIs, apis...)
|
||||||
} else {
|
} else {
|
||||||
a.Apis = apis
|
a.APIs = apis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if models, ok := modelsList[cname]; ok {
|
if models, ok := modelsList[cname]; ok {
|
||||||
for _, m := range models {
|
for _, m := range models {
|
||||||
a.Models[m.Id] = m
|
a.Models[m.ID] = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ func isSystemPackage(pkgpath string) bool {
|
|||||||
|
|
||||||
// parse the func comments
|
// parse the func comments
|
||||||
func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpath string) error {
|
func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpath string) error {
|
||||||
innerapi := swagger.Api{}
|
innerapi := swagger.API{}
|
||||||
opts := swagger.Operation{}
|
opts := swagger.Operation{}
|
||||||
if comments != nil && comments.List != nil {
|
if comments != nil && comments.List != nil {
|
||||||
for _, c := range comments.List {
|
for _, c := range comments.List {
|
||||||
@ -369,9 +369,9 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
|||||||
innerapi.Path = e1[0]
|
innerapi.Path = e1[0]
|
||||||
if len(e1) == 2 && e1[1] != "" {
|
if len(e1) == 2 && e1[1] != "" {
|
||||||
e1 = strings.SplitN(e1[1], " ", 2)
|
e1 = strings.SplitN(e1[1], " ", 2)
|
||||||
opts.HttpMethod = strings.ToUpper(strings.Trim(e1[0], "[]"))
|
opts.HTTPMethod = strings.ToUpper(strings.Trim(e1[0], "[]"))
|
||||||
} else {
|
} else {
|
||||||
opts.HttpMethod = "GET"
|
opts.HTTPMethod = "GET"
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(t, "@Title") {
|
} else if strings.HasPrefix(t, "@Title") {
|
||||||
opts.Nickname = strings.TrimSpace(t[len("@Title"):])
|
opts.Nickname = strings.TrimSpace(t[len("@Title"):])
|
||||||
@ -490,7 +490,7 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
|||||||
if _, ok := controllerList[pkgpath+controllerName]; ok {
|
if _, ok := controllerList[pkgpath+controllerName]; ok {
|
||||||
controllerList[pkgpath+controllerName] = append(controllerList[pkgpath+controllerName], innerapi)
|
controllerList[pkgpath+controllerName] = append(controllerList[pkgpath+controllerName], innerapi)
|
||||||
} else {
|
} else {
|
||||||
controllerList[pkgpath+controllerName] = make([]swagger.Api, 1)
|
controllerList[pkgpath+controllerName] = make([]swagger.API, 1)
|
||||||
controllerList[pkgpath+controllerName][0] = innerapi
|
controllerList[pkgpath+controllerName][0] = innerapi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,7 +561,7 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m.Id = k
|
m.ID = k
|
||||||
if st.Fields.List != nil {
|
if st.Fields.List != nil {
|
||||||
m.Properties = make(map[string]swagger.ModelProperty)
|
m.Properties = make(map[string]swagger.ModelProperty)
|
||||||
for _, field := range st.Fields.List {
|
for _, field := range st.Fields.List {
|
||||||
@ -635,7 +635,7 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
ColorLog("can't find the object: %v", str)
|
ColorLog("can't find the object: %v", str)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user