Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip unexported struct fields in swaggergen #841

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Skip unexported struct fields in swaggergen
Go JSON serialization only handles exported struct fields.
  • Loading branch information
de1acr0ix committed Jan 17, 2023
commit 06eb48f6b9bf880aaf672b19c716b4e992105a3e
14 changes: 13 additions & 1 deletion generate/swaggergen/g_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down