mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
Merge pull request #26 from sandysong/master
修正Model循环引用导致generate死循环的问题
This commit is contained in:
commit
ba0d690eac
23
g_docs.go
23
g_docs.go
@ -99,7 +99,7 @@ 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][]swagger.Model
|
var modelsList map[string]map[string]swagger.Model
|
||||||
var rootapi swagger.ResourceListing
|
var rootapi swagger.ResourceListing
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -109,7 +109,7 @@ func init() {
|
|||||||
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][]swagger.Model)
|
modelsList = make(map[string]map[string]swagger.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateDocs(curpath string) {
|
func generateDocs(curpath string) {
|
||||||
@ -381,9 +381,9 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
|||||||
//opts.Type = ll[len(ll)-1]
|
//opts.Type = ll[len(ll)-1]
|
||||||
rs.ResponseModel = m
|
rs.ResponseModel = m
|
||||||
if _, ok := modelsList[pkgpath+controllerName]; !ok {
|
if _, ok := modelsList[pkgpath+controllerName]; !ok {
|
||||||
modelsList[pkgpath+controllerName] = make([]swagger.Model, 0)
|
modelsList[pkgpath+controllerName] = make(map[string]swagger.Model, 0)
|
||||||
}
|
}
|
||||||
modelsList[pkgpath+controllerName] = append(modelsList[pkgpath+controllerName], mod)
|
modelsList[pkgpath+controllerName][st[2]] = mod
|
||||||
appendModels(cmpath, pkgpath, controllerName, realTypes)
|
appendModels(cmpath, pkgpath, controllerName, realTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,14 +626,21 @@ func grepJsonTag(tag string) string {
|
|||||||
|
|
||||||
// append models
|
// append models
|
||||||
func appendModels(cmpath, pkgpath, controllerName string, realTypes []string) {
|
func appendModels(cmpath, pkgpath, controllerName string, realTypes []string) {
|
||||||
|
var p string
|
||||||
|
if cmpath != "" {
|
||||||
|
p = strings.Join(strings.Split(cmpath, "/"), ".") + "."
|
||||||
|
} else {
|
||||||
|
p = ""
|
||||||
|
}
|
||||||
for _, realType := range realTypes {
|
for _, realType := range realTypes {
|
||||||
if realType != "" && !isBasicType(strings.TrimLeft(realType, "[]")) &&
|
if realType != "" && !isBasicType(strings.TrimLeft(realType, "[]")) &&
|
||||||
!strings.HasPrefix(realType, "map") && !strings.HasPrefix(realType, "&") {
|
!strings.HasPrefix(realType, "map") && !strings.HasPrefix(realType, "&") {
|
||||||
if cmpath != "" {
|
if _, ok := modelsList[pkgpath+controllerName][p+realType]; ok {
|
||||||
cmpath = strings.Join(strings.Split(cmpath, "/"), ".") + "."
|
continue
|
||||||
}
|
}
|
||||||
_, _, mod, newRealTypes := getModel(cmpath + realType)
|
fmt.Printf(pkgpath+":"+controllerName+":"+cmpath+":"+realType+"\n")
|
||||||
modelsList[pkgpath+controllerName] = append(modelsList[pkgpath+controllerName], mod)
|
_, _, mod, newRealTypes := getModel(p+realType)
|
||||||
|
modelsList[pkgpath+controllerName][p+realType] = mod
|
||||||
appendModels(cmpath, pkgpath, controllerName, newRealTypes)
|
appendModels(cmpath, pkgpath, controllerName, newRealTypes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user