Skip to content
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
8 changes: 6 additions & 2 deletions net/goai/goai_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
}

// Remove operation body duplicated properties.
oai.removeOperationDuplicatedProperties(operation)
oai.removeOperationDuplicatedProperties(&operation)

// Assign to certain operation attribute.
switch gstr.ToUpper(in.Method) {
Expand Down Expand Up @@ -317,7 +317,7 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
return nil
}

func (oai *OpenApiV3) removeOperationDuplicatedProperties(operation Operation) {
func (oai *OpenApiV3) removeOperationDuplicatedProperties(operation *Operation) {
if len(operation.Parameters) == 0 {
// Nothing to do.
return
Expand Down Expand Up @@ -352,6 +352,10 @@ func (oai *OpenApiV3) removeOperationDuplicatedProperties(operation Operation) {
requestBodyContent.Schema.Value = newSchema
newSchema.Required = oai.removeItemsFromArray(newSchema.Required, duplicatedParameterNames)
newSchema.Properties.Removes(duplicatedParameterNames)
// remove request body if there are no properties left
if newSchema.Properties.refs.IsEmpty() {
operation.RequestBody = nil
}
continue
}
}
Expand Down
56 changes: 56 additions & 0 deletions net/goai/goai_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,59 @@ func Test_Issue3235(t *testing.T) {
"test user desc")
})
}

type Issue4247NoBodyReq struct {
g.Meta `path:"/cluster/{cluster_id}/node/{name}/drain" method:"post" tags:"节点管理" summary:"驱逐节点" dc:"该接口会先设置节点不可调度,再进行驱逐"`
ClusterId string `json:"cluster_id" v:"required" dc:"集群ID" `
Name string `json:"name" v:"required" dc:"节点名称"`
}
type Issue4247NoBodyRes struct{}

type Issue4247HasBodyReq struct {
g.Meta `path:"/cluster/{cluster_id}/node/{name}/join" method:"post" tags:"节点管理" summary:"增加节点" dc:"增加节点"`
ClusterId string `json:"cluster_id" v:"required" dc:"集群ID" `
Name string `json:"name" v:"required" dc:"节点名称"`
Type string `json:"type" v:"required" dc:"节点类型"`
}
type Issue4247HasBodyRes struct{}

type Issue4247 struct{}

func (Issue4247) Issue4247NoBody(ctx context.Context, req *Issue4247NoBodyReq) (res *Issue4247NoBodyRes, err error) {
res = &Issue4247NoBodyRes{}
return
}

func (Issue4247) Issue4247HasBody(ctx context.Context, req *Issue4247HasBodyReq) (res *Issue4247HasBodyRes, err error) {
res = &Issue4247HasBodyRes{}
return
}

// https://github.com/gogf/gf/issues/4247
func Test_Issue4247(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
s := g.Server(guid.S())
s.Use(ghttp.MiddlewareHandlerResponse)
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(
new(Issue4247),
)
})
s.SetLogger(nil)
s.SetOpenApiPath("/api.json")
s.SetDumpRouterMap(false)
s.Start()

defer s.Shutdown()
time.Sleep(100 * time.Millisecond)

c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
apiContent := c.GetBytes(ctx, "/api.json")
j, err := gjson.LoadJson(apiContent)
t.AssertNil(err)
requestBody := `{"content":{"application/json":{"schema":{"description":"增加节点","properties":{"type":{"description":"节点类型","format":"string","type":"string"}},"required":["type"],"type":"object"}}}}`
t.Assert(j.Get(`paths./cluster/{cluster_id}/node/{name}/drain.post.requestBody`).IsEmpty(), true)
t.Assert(j.Get(`paths./cluster/{cluster_id}/node/{name}/join.post.requestBody`).String(), requestBody)
})
}
Loading