mirror of
https://github.com/casbin/bee.git
synced 2025-05-24 08:20:32 +08:00
fix: support interface type (#3)
* fix:fix the swagger docs about casdoor Signed-off-by: baihhh <2542274498@qq.com> * Update g_docs.go --------- Signed-off-by: baihhh <2542274498@qq.com> Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
parent
f758255a2e
commit
ce32a9616d
@ -49,9 +49,10 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
astTypeArray = "array"
|
||||
astTypeObject = "object"
|
||||
astTypeMap = "map"
|
||||
astTypeArray = "array"
|
||||
astTypeObject = "object"
|
||||
astTypeMap = "map"
|
||||
astTypeInterface = "interface"
|
||||
)
|
||||
|
||||
var pkgCache map[string]struct{} //pkg:controller:function:comments comments: key:value
|
||||
@ -973,6 +974,11 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string
|
||||
if isBasicType(fmt.Sprint(t.Elt)) {
|
||||
typeFormat := strings.Split(basicTypes[fmt.Sprint(t.Elt)], ":")
|
||||
m.Format = typeFormat[0]
|
||||
} else if _, ok := t.Elt.(*ast.InterfaceType); ok {
|
||||
objectName := packageName + "." + k
|
||||
m.Items = &swagger.Schema{
|
||||
Ref: "#/definitions/" + objectName,
|
||||
}
|
||||
} else {
|
||||
objectName := packageName + "." + fmt.Sprint(t.Elt)
|
||||
if _, ok := rootapi.Definitions[objectName]; !ok {
|
||||
@ -1116,6 +1122,11 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
|
||||
Type: typeFormat[0],
|
||||
Format: typeFormat[1],
|
||||
}
|
||||
} else if sType == astTypeInterface {
|
||||
mp.AdditionalProperties = &swagger.Propertie{
|
||||
Type: "string",
|
||||
Description: "support string, struct or []struct",
|
||||
}
|
||||
}
|
||||
}
|
||||
if field.Names != nil {
|
||||
@ -1232,6 +1243,9 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
||||
if star, ok := arr.Elt.(*ast.StarExpr); ok {
|
||||
return true, fmt.Sprint(star.X), astTypeObject
|
||||
}
|
||||
if _, ok := arr.Elt.(*ast.InterfaceType); ok {
|
||||
return true, astTypeObject, astTypeObject
|
||||
}
|
||||
return true, fmt.Sprint(arr.Elt), astTypeObject
|
||||
}
|
||||
switch t := f.Type.(type) {
|
||||
@ -1250,6 +1264,8 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
|
||||
return false, astTypeMap, basicTypes[val]
|
||||
}
|
||||
return false, val, astTypeObject
|
||||
case *ast.InterfaceType:
|
||||
return false, astTypeObject, astTypeInterface
|
||||
}
|
||||
basicType := fmt.Sprint(f.Type)
|
||||
if object, isStdLibObject := stdlibObject[basicType]; isStdLibObject {
|
||||
|
Loading…
x
Reference in New Issue
Block a user