Skip to content

Commit

Permalink
fix: disable map tag summary and description from the OpenAPI `Op…
Browse files Browse the repository at this point in the history
…eration` to `PathItem` (#2823)
  • Loading branch information
WankkoRee authored Aug 2, 2023
1 parent 0f53660 commit 4791581
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 14 additions & 1 deletion net/goai/goai_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package goai

import (
"github.com/gogf/gf/v2/container/gmap"
"net/http"
"reflect"

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions net/goai/goai_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"区域"`
Expand Down Expand Up @@ -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, `实例名称`)
})
Expand Down

0 comments on commit 4791581

Please sign in to comment.