diff --git a/net/goai/goai_path.go b/net/goai/goai_path.go index 4ffcc8415a0..97188322d89 100644 --- a/net/goai/goai_path.go +++ b/net/goai/goai_path.go @@ -7,6 +7,7 @@ package goai import ( + "github.com/gogf/gf/v2/container/gmap" "net/http" "reflect" @@ -134,9 +135,21 @@ func (oai *OpenApiV3) addPath(in addPathInput) error { } if len(inputMetaMap) > 0 { - if err := oai.tagMapToPath(inputMetaMap, &path); err != nil { + // Path and Operation are not the same thing, so it is necessary to copy a Meta for Path from Operation and edit it. + // And you know, we set the Summary and Description for Operation, not for Path, so we need to remove them. + inputMetaMapForPath := gmap.NewStrStrMapFrom(inputMetaMap).Clone() + inputMetaMapForPath.Removes([]string{ + gtag.SummaryShort, + gtag.SummaryShort2, + gtag.Summary, + gtag.DescriptionShort, + gtag.DescriptionShort2, + gtag.Description, + }) + if err := oai.tagMapToPath(inputMetaMapForPath.Map(), &path); err != nil { return err } + if err := oai.tagMapToOperation(inputMetaMap, &operation); err != nil { return err } diff --git a/net/goai/goai_z_unit_test.go b/net/goai/goai_z_unit_test.go index 86393119c59..34bafa4e59a 100644 --- a/net/goai/goai_z_unit_test.go +++ b/net/goai/goai_z_unit_test.go @@ -671,7 +671,7 @@ func TestOpenApiV3_ShortTags(t *testing.T) { } type CreateResourceReq struct { CommonReq - gmeta.Meta `path:"/CreateResourceReq" method:"POST" tags:"default" sm:"CreateResourceReq sum"` + gmeta.Meta `path:"/CreateResourceReq" method:"POST" tags:"default" sm:"CreateResourceReq sum" dc:"CreateResourceReq des"` Name string `dc:"实例名称"` Product string `dc:"业务类型"` Region string `v:"required" dc:"区域"` @@ -709,7 +709,10 @@ func TestOpenApiV3_ShortTags(t *testing.T) { // fmt.Println(oai.String()) // Schema asserts. t.Assert(len(oai.Components.Schemas.Map()), 3) - t.Assert(oai.Paths[`/test1/{appId}`].Summary, `CreateResourceReq sum`) + t.Assert(oai.Paths[`/test1/{appId}`].Summary, ``) + t.Assert(oai.Paths[`/test1/{appId}`].Description, ``) + t.Assert(oai.Paths[`/test1/{appId}`].Put.Summary, `CreateResourceReq sum`) + t.Assert(oai.Paths[`/test1/{appId}`].Put.Description, `CreateResourceReq des`) t.Assert(oai.Paths[`/test1/{appId}`].Put.Parameters[1].Value.Schema.Value.Description, `资源Id`) t.Assert(oai.Components.Schemas.Get(`github.com.gogf.gf.v2.net.goai_test.CreateResourceReq`).Value.Properties.Get(`Name`).Value.Description, `实例名称`) })