mirror of
https://github.com/beego/bee.git
synced 2024-11-23 01:30:55 +00:00
Fix typeAnalyser
- replace 'f.Type' with 'star.X' if 'f.Type.(*ast.StarExpr)' - set 'isSlice' to true if 'arr.Elt' is basic type Signed-off-by: weiyang <weiyang.ones@gmail.com>
This commit is contained in:
parent
f7d2e04e07
commit
74c9b520de
28
g_docs.go
28
g_docs.go
@ -758,9 +758,16 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
||||||
if arr, ok := f.Type.(*ast.ArrayType); ok {
|
fType := f.Type
|
||||||
|
if star, ok := fType.(*ast.StarExpr); ok {
|
||||||
|
fType = star.X
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t := fType.(type) {
|
||||||
|
case *ast.ArrayType:
|
||||||
|
arr := fType.(*ast.ArrayType)
|
||||||
if isBasicType(fmt.Sprint(arr.Elt)) {
|
if isBasicType(fmt.Sprint(arr.Elt)) {
|
||||||
return false, fmt.Sprintf("[]%v", arr.Elt), basicTypes[fmt.Sprint(arr.Elt)]
|
return true, fmt.Sprint(arr.Elt), basicTypes[fmt.Sprint(arr.Elt)]
|
||||||
}
|
}
|
||||||
if mp, ok := arr.Elt.(*ast.MapType); ok {
|
if mp, ok := arr.Elt.(*ast.MapType); ok {
|
||||||
return false, fmt.Sprintf("map[%v][%v]", mp.Key, mp.Value), "object"
|
return false, fmt.Sprintf("map[%v][%v]", mp.Key, mp.Value), "object"
|
||||||
@ -769,21 +776,22 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
|||||||
return true, fmt.Sprint(star.X), "object"
|
return true, fmt.Sprint(star.X), "object"
|
||||||
}
|
}
|
||||||
return true, fmt.Sprint(arr.Elt), "object"
|
return true, fmt.Sprint(arr.Elt), "object"
|
||||||
}
|
|
||||||
switch t := f.Type.(type) {
|
|
||||||
case *ast.StarExpr:
|
|
||||||
return false, fmt.Sprint(t.X), "object"
|
|
||||||
case *ast.MapType:
|
case *ast.MapType:
|
||||||
val := fmt.Sprintf("%v", t.Value)
|
var val string
|
||||||
|
if star, ok := t.Value.(*ast.StarExpr); ok {
|
||||||
|
val = fmt.Sprint(star.X)
|
||||||
|
} else {
|
||||||
|
val = fmt.Sprint(t.Value)
|
||||||
|
}
|
||||||
if isBasicType(val) {
|
if isBasicType(val) {
|
||||||
return false, "map", basicTypes[val]
|
return false, "map", basicTypes[val]
|
||||||
}
|
}
|
||||||
return false, val, "object"
|
return false, val, "object"
|
||||||
}
|
}
|
||||||
if k, ok := basicTypes[fmt.Sprint(f.Type)]; ok {
|
if k, ok := basicTypes[fmt.Sprint(fType)]; ok {
|
||||||
return false, fmt.Sprint(f.Type), k
|
return false, fmt.Sprint(fType), k
|
||||||
}
|
}
|
||||||
return false, fmt.Sprint(f.Type), "object"
|
return false, fmt.Sprint(fType), "object"
|
||||||
}
|
}
|
||||||
|
|
||||||
func isBasicType(Type string) bool {
|
func isBasicType(Type string) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user