fix: disable map tag summary and description from the OpenAPI Operation to PathItem (#2823)

This commit is contained in:
Wankko Ree
2023-08-02 20:45:58 +08:00
committed by GitHub
parent 0f53660453
commit 47915816b5
2 changed files with 19 additions and 3 deletions

View File

@ -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
}

View File

@ -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, `实例名称`)
})