mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
support tag beedoc to support required
This commit is contained in:
parent
33eaf8c2b7
commit
b13c2068a9
15
g_docs.go
15
g_docs.go
@ -24,6 +24,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -535,9 +536,13 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
var name = field.Names[0].Name
|
var name = field.Names[0].Name
|
||||||
if field.Tag != nil {
|
if field.Tag != nil {
|
||||||
mp.Description = strings.Trim(field.Tag.Value, "`")
|
mp.Description = strings.Trim(field.Tag.Value, "`")
|
||||||
if tag := grepJsonTag(strings.TrimLeft(field.Tag.Value, `json:"`)); tag != "" {
|
stag := reflect.StructTag(mp.Description)
|
||||||
|
if tag := stag.Get("json"); tag != "" {
|
||||||
name = tag
|
name = tag
|
||||||
}
|
}
|
||||||
|
if beedoc := stag.Get("beedoc"); beedoc == "required" {
|
||||||
|
m.Required = append(m.Required, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Properties[name] = mp
|
m.Properties[name] = mp
|
||||||
}
|
}
|
||||||
@ -558,10 +563,10 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
func typeAnalyser(f *ast.Field) (isSlice bool, realType string) {
|
func typeAnalyser(f *ast.Field) (isSlice bool, realType string) {
|
||||||
if arr, ok := f.Type.(*ast.ArrayType); ok {
|
if arr, ok := f.Type.(*ast.ArrayType); ok {
|
||||||
if isBasicType(fmt.Sprint(arr.Elt)) {
|
if isBasicType(fmt.Sprint(arr.Elt)) {
|
||||||
return false, ""
|
return false, fmt.Sprintf("[]%v", arr.Elt)
|
||||||
}
|
}
|
||||||
if _, ok := arr.Elt.(*ast.MapType); ok {
|
if mp, ok := arr.Elt.(*ast.MapType); ok {
|
||||||
return false, ""
|
return false, fmt.Sprintf("map[%v][%v]", mp.Key, mp.Value)
|
||||||
}
|
}
|
||||||
if star, ok := arr.Elt.(*ast.StarExpr); ok {
|
if star, ok := arr.Elt.(*ast.StarExpr); ok {
|
||||||
return true, fmt.Sprint(star.X)
|
return true, fmt.Sprint(star.X)
|
||||||
@ -606,7 +611,7 @@ 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) {
|
||||||
for _, realType := range realTypes {
|
for _, realType := range realTypes {
|
||||||
if realType != "" && strings.HasPrefix(realType, "[]") {
|
if realType != "" && strings.HasPrefix(realType, "[]") && !isBasicType(strings.TrimLeft(realType, "[]")) {
|
||||||
if cmpath != "" {
|
if cmpath != "" {
|
||||||
cmpath = strings.Join(strings.Split(cmpath, "/"), ".") + "."
|
cmpath = strings.Join(strings.Split(cmpath, "/"), ".") + "."
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user