From 8972f7e9d71657f5b931947990eea4c0a0086963 Mon Sep 17 00:00:00 2001 From: wlynxg Date: Thu, 21 Nov 2024 20:40:58 +0800 Subject: [PATCH 1/2] fix: even if an embedded structure carries a tag, it is expanded as a property of the parent structure. --- net/goai/goai_shema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/goai/goai_shema.go b/net/goai/goai_shema.go index f8a6be2d831..042e0f21537 100644 --- a/net/goai/goai_shema.go +++ b/net/goai/goai_shema.go @@ -176,7 +176,7 @@ func (oai *OpenApiV3) structToSchema(object interface{}) (*Schema, error) { // struct. structFields, _ := gstructs.Fields(gstructs.FieldsInput{ Pointer: object, - RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag, + RecursiveOption: gstructs.RecursiveOptionEmbedded, }) schema.Type = TypeObject for _, structField := range structFields { From 8dfe5d650cf791e68615d89a0b7e107a186b2849 Mon Sep 17 00:00:00 2001 From: wlynxg Date: Thu, 21 Nov 2024 23:24:41 +0800 Subject: [PATCH 2/2] test: unit test for issue 3930 --- net/goai/goai_z_unit_issue_test.go | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/net/goai/goai_z_unit_issue_test.go b/net/goai/goai_z_unit_issue_test.go index c3d28ee2c87..6128d57fbf7 100644 --- a/net/goai/goai_z_unit_issue_test.go +++ b/net/goai/goai_z_unit_issue_test.go @@ -231,3 +231,47 @@ func Test_Issue3747(t *testing.T) { t.Assert(schema, Issue3747Res403Schema) }) } + +type Issue3930DefaultReq struct { + g.Meta `path:"/user/{id}" method:"get" tags:"User" summary:"Get one user"` + Id int64 `v:"required" dc:"user id"` +} +type Issue3930DefaultRes struct { + *Issue3930User `dc:"user"` +} +type Issue3930User struct { + Id uint `json:"id" orm:"id" description:"user id"` // user id +} + +type Issue3930 struct{} + +func (Issue3930) Default(ctx context.Context, req *Issue3930DefaultReq) (res *Issue3930DefaultRes, err error) { + res = &Issue3930DefaultRes{} + return +} + +// https://github.com/gogf/gf/issues/3930 +func Test_Issue3930(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + s := g.Server(guid.S()) + s.Use(ghttp.MiddlewareHandlerResponse) + s.Group("/", func(group *ghttp.RouterGroup) { + group.Bind( + new(Issue3930), + ) + }) + s.SetLogger(nil) + s.SetOpenApiPath("/api.json") + s.SetDumpRouterMap(false) + s.Start() + defer s.Shutdown() + + time.Sleep(100 * time.Millisecond) + + var ( + api = s.GetOpenApi() + reqPath = "github.com.gogf.gf.v2.net.goai_test.Issue3930DefaultRes" + ) + t.AssertNE(api.Components.Schemas.Get(reqPath).Value.Properties.Get("id"), nil) + }) +}