Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
gqcn marked this conversation as resolved.
Show resolved Hide resolved
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
Loading