mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix: disable map tag summary and description from the OpenAPI Operation to PathItem (#2823)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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, `实例名称`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user