mirror of
https://github.com/beego/bee.git
synced 2024-11-25 20:10:55 +00:00
commit
6189e101c9
@ -650,7 +650,8 @@ func checkEnv(appname string) (apppath, packpath string, err error) {
|
||||
for _, gpath := range gps {
|
||||
gsrcpath := path.Join(gpath, "src")
|
||||
if strings.HasPrefix(currpath, gsrcpath) {
|
||||
return currpath, currpath[len(gsrcpath)+1:], nil
|
||||
packpath = strings.Replace(currpath[len(gsrcpath)+1:], string(path.Separator), "/", -1)
|
||||
return currpath, packpath, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
2
bee.go
2
bee.go
@ -25,7 +25,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const version = "1.5.0"
|
||||
const version = "1.5.1"
|
||||
|
||||
type Command struct {
|
||||
// Run runs the command.
|
||||
|
16
g_appcode.go
16
g_appcode.go
@ -1168,11 +1168,12 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// oprations for {{ctrlName}}
|
||||
// {{ctrlName}}Controller oprations for {{ctrlName}}
|
||||
type {{ctrlName}}Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// URLMapping ...
|
||||
func (c *{{ctrlName}}Controller) URLMapping() {
|
||||
c.Mapping("Post", c.Post)
|
||||
c.Mapping("GetOne", c.GetOne)
|
||||
@ -1181,6 +1182,7 @@ func (c *{{ctrlName}}Controller) URLMapping() {
|
||||
c.Mapping("Delete", c.Delete)
|
||||
}
|
||||
|
||||
// Post ...
|
||||
// @Title Post
|
||||
// @Description create {{ctrlName}}
|
||||
// @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content"
|
||||
@ -1202,7 +1204,8 @@ func (c *{{ctrlName}}Controller) Post() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// GetOne ...
|
||||
// @Title Get One
|
||||
// @Description get {{ctrlName}} by id
|
||||
// @Param id path string true "The key for staticblock"
|
||||
// @Success 200 {object} models.{{ctrlName}}
|
||||
@ -1220,6 +1223,7 @@ func (c *{{ctrlName}}Controller) GetOne() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// GetAll ...
|
||||
// @Title Get All
|
||||
// @Description get {{ctrlName}}
|
||||
// @Param query query string false "Filter. e.g. col1:v1,col2:v2 ..."
|
||||
@ -1235,9 +1239,9 @@ func (c *{{ctrlName}}Controller) GetAll() {
|
||||
var fields []string
|
||||
var sortby []string
|
||||
var order []string
|
||||
var query map[string]string = make(map[string]string)
|
||||
var query = make(map[string]string)
|
||||
var limit int64 = 10
|
||||
var offset int64 = 0
|
||||
var offset int64
|
||||
|
||||
// fields: col1,col2,entity.col3
|
||||
if v := c.GetString("fields"); v != "" {
|
||||
@ -1282,7 +1286,8 @@ func (c *{{ctrlName}}Controller) GetAll() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// Put ...
|
||||
// @Title Put
|
||||
// @Description update the {{ctrlName}}
|
||||
// @Param id path string true "The id you want to update"
|
||||
// @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content"
|
||||
@ -1305,6 +1310,7 @@ func (c *{{ctrlName}}Controller) Put() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
// @Title Delete
|
||||
// @Description delete the {{ctrlName}}
|
||||
// @Param id path string true "The id you want to delete"
|
||||
|
@ -82,11 +82,12 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// operations for {{controllerName}}
|
||||
// {{controllerName}}Controller operations for {{controllerName}}
|
||||
type {{controllerName}}Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// URLMapping ...
|
||||
func (c *{{controllerName}}Controller) URLMapping() {
|
||||
c.Mapping("Post", c.Post)
|
||||
c.Mapping("GetOne", c.GetOne)
|
||||
@ -95,6 +96,7 @@ func (c *{{controllerName}}Controller) URLMapping() {
|
||||
c.Mapping("Delete", c.Delete)
|
||||
}
|
||||
|
||||
// Post ...
|
||||
// @Title Create
|
||||
// @Description create {{controllerName}}
|
||||
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
||||
@ -105,6 +107,7 @@ func (c *{{controllerName}}Controller) Post() {
|
||||
|
||||
}
|
||||
|
||||
// GetOne ...
|
||||
// @Title GetOne
|
||||
// @Description get {{controllerName}} by id
|
||||
// @Param id path string true "The key for staticblock"
|
||||
@ -115,6 +118,7 @@ func (c *{{controllerName}}Controller) GetOne() {
|
||||
|
||||
}
|
||||
|
||||
// GetAll ...
|
||||
// @Title GetAll
|
||||
// @Description get {{controllerName}}
|
||||
// @Param query query string false "Filter. e.g. col1:v1,col2:v2 ..."
|
||||
@ -130,7 +134,8 @@ func (c *{{controllerName}}Controller) GetAll() {
|
||||
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// Put ...
|
||||
// @Title Put
|
||||
// @Description update the {{controllerName}}
|
||||
// @Param id path string true "The id you want to update"
|
||||
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
||||
@ -141,6 +146,7 @@ func (c *{{controllerName}}Controller) Put() {
|
||||
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
// @Title Delete
|
||||
// @Description delete the {{controllerName}}
|
||||
// @Param id path string true "The id you want to delete"
|
||||
@ -164,11 +170,12 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// oprations for {{controllerName}}
|
||||
// {{controllerName}}Controller oprations for {{controllerName}}
|
||||
type {{controllerName}}Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// URLMapping ...
|
||||
func (c *{{controllerName}}Controller) URLMapping() {
|
||||
c.Mapping("Post", c.Post)
|
||||
c.Mapping("GetOne", c.GetOne)
|
||||
@ -177,6 +184,7 @@ func (c *{{controllerName}}Controller) URLMapping() {
|
||||
c.Mapping("Delete", c.Delete)
|
||||
}
|
||||
|
||||
// Post ...
|
||||
// @Title Post
|
||||
// @Description create {{controllerName}}
|
||||
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
||||
@ -195,7 +203,8 @@ func (c *{{controllerName}}Controller) Post() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// GetOne ...
|
||||
// @Title Get One
|
||||
// @Description get {{controllerName}} by id
|
||||
// @Param id path string true "The key for staticblock"
|
||||
// @Success 200 {object} models.{{controllerName}}
|
||||
@ -213,6 +222,7 @@ func (c *{{controllerName}}Controller) GetOne() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// GetAll ...
|
||||
// @Title Get All
|
||||
// @Description get {{controllerName}}
|
||||
// @Param query query string false "Filter. e.g. col1:v1,col2:v2 ..."
|
||||
@ -228,9 +238,9 @@ func (c *{{controllerName}}Controller) GetAll() {
|
||||
var fields []string
|
||||
var sortby []string
|
||||
var order []string
|
||||
var query map[string]string = make(map[string]string)
|
||||
var query = make(map[string]string)
|
||||
var limit int64 = 10
|
||||
var offset int64 = 0
|
||||
var offset int64
|
||||
|
||||
// fields: col1,col2,entity.col3
|
||||
if v := c.GetString("fields"); v != "" {
|
||||
@ -275,7 +285,8 @@ func (c *{{controllerName}}Controller) GetAll() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// Put ...
|
||||
// @Title Put
|
||||
// @Description update the {{controllerName}}
|
||||
// @Param id path string true "The id you want to update"
|
||||
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
||||
@ -295,6 +306,7 @@ func (c *{{controllerName}}Controller) Put() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
// @Title Delete
|
||||
// @Description delete the {{controllerName}}
|
||||
// @Param id path string true "The id you want to delete"
|
||||
|
45
g_docs.go
45
g_docs.go
@ -365,7 +365,9 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
||||
} else if strings.HasPrefix(t, "@Title") {
|
||||
opts.OperationID = controllerName + "." + strings.TrimSpace(t[len("@Title"):])
|
||||
} else if strings.HasPrefix(t, "@Description") {
|
||||
opts.Summary = strings.TrimSpace(t[len("@Description"):])
|
||||
opts.Description = strings.TrimSpace(t[len("@Description"):])
|
||||
} else if strings.HasPrefix(t, "@Summary") {
|
||||
opts.Summary = strings.TrimSpace(t[len("@Summary"):])
|
||||
} else if strings.HasPrefix(t, "@Success") {
|
||||
ss := strings.TrimSpace(t[len("@Success"):])
|
||||
rs := swagger.Response{}
|
||||
@ -610,6 +612,24 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
|
||||
if k != objectname {
|
||||
continue
|
||||
}
|
||||
parseObject(d, k, &m, &realTypes, astPkgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Title == "" {
|
||||
ColorLog("[WARN]can't find the object: %s\n", str)
|
||||
// TODO remove when all type have been supported
|
||||
//os.Exit(1)
|
||||
}
|
||||
if len(rootapi.Definitions) == 0 {
|
||||
rootapi.Definitions = make(map[string]swagger.Schema)
|
||||
}
|
||||
rootapi.Definitions[objectname] = m
|
||||
return
|
||||
}
|
||||
|
||||
func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string, astPkgs map[string]*ast.Package) {
|
||||
ts, ok := d.Decl.(*ast.TypeSpec)
|
||||
if !ok {
|
||||
ColorLog("Unknown type without TypeSec: %v\n", d)
|
||||
@ -618,16 +638,15 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
|
||||
// TODO support other types, such as `ArrayType`, `MapType`, `InterfaceType` etc...
|
||||
st, ok := ts.Type.(*ast.StructType)
|
||||
if !ok {
|
||||
continue
|
||||
return
|
||||
}
|
||||
m.Title = k
|
||||
if st.Fields.List != nil {
|
||||
m.Properties = make(map[string]swagger.Propertie)
|
||||
for _, field := range st.Fields.List {
|
||||
isSlice, realType, sType := typeAnalyser(field)
|
||||
realTypes = append(realTypes, realType)
|
||||
*realTypes = append(*realTypes, realType)
|
||||
mp := swagger.Propertie{}
|
||||
// add type slice
|
||||
if isSlice {
|
||||
mp.Type = "array"
|
||||
if isBasicType(realType) {
|
||||
@ -650,8 +669,6 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
|
||||
mp.Ref = "#/definitions/" + realType
|
||||
}
|
||||
}
|
||||
|
||||
// dont add property if anonymous field
|
||||
if field.Names != nil {
|
||||
|
||||
// set property name as field name
|
||||
@ -697,6 +714,12 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
|
||||
if ignore := stag.Get("ignore"); ignore != "" {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
for _, pkg := range astPkgs {
|
||||
for _, fl := range pkg.Files {
|
||||
for nameOfObj, obj := range fl.Scope.Objects {
|
||||
if obj.Name == fmt.Sprint(field.Type) {
|
||||
parseObject(obj, nameOfObj, m, realTypes, astPkgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -704,16 +727,6 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Schema, realTyp
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Title == "" {
|
||||
ColorLog("[WARN]can't find the object: %s\n", str)
|
||||
// TODO remove when all type have been supported
|
||||
//os.Exit(1)
|
||||
}
|
||||
if len(rootapi.Definitions) == 0 {
|
||||
rootapi.Definitions = make(map[string]swagger.Schema)
|
||||
}
|
||||
rootapi.Definitions[objectname] = m
|
||||
return
|
||||
}
|
||||
|
||||
func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
||||
|
Loading…
Reference in New Issue
Block a user