1
0
mirror of https://github.com/beego/bee.git synced 2024-11-01 00:00:53 +00:00

Skip unexported struct fields in swaggergen

Go JSON serialization only handles exported struct fields.
This commit is contained in:
Hanjiang Yu 2023-01-17 14:46:23 +08:00
parent ebb8c0ad31
commit 06eb48f6b9

View File

@ -37,9 +37,10 @@ import (
bu "github.com/beego/bee/v2/utils"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web/swagger"
beeLogger "github.com/beego/bee/v2/logger"
)
const (
@ -1092,6 +1093,17 @@ func parseStruct(imports []*ast.ImportSpec, st *ast.StructType, k string, m *swa
if st.Fields.List != nil {
m.Properties = make(map[string]swagger.Propertie)
for _, field := range st.Fields.List {
// skip processing if field is not exported
var exported = field.Names == nil
for _, ident := range field.Names {
if ident.IsExported() {
exported = true
}
}
if !exported {
continue
}
isSlice, realType, sType := typeAnalyser(field)
if (isSlice && isBasicType(realType)) || sType == astTypeObject {
if len(strings.Split(realType, " ")) > 1 {