gf icon indicating copy to clipboard operation
gf copied to clipboard

net/ghttp: openapi doc misses request parameter constraints when `CommonRequest` is set.

Open jswxstw opened this issue 1 year ago • 2 comments

Go version

go version go1.21.3 darwin/amd64

GoFrame version

2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

func (c *cMain) enhanceOpenAPIDoc(s *ghttp.Server) {
	openapi := s.GetOpenApi()
        // CommonRequest is set to QCloudV3CommonReq.
	openapi.Config.CommonRequest = QCloudV3CommonReq{}
	openapi.Config.CommonResponse = QCloudV3CommonRes{}
	openapi.Config.CommonResponseDataField = `Response.`
}
type QCloudV3CommonReq struct {
	AppId         int64  `description:"云API参数:应用Id"`
	RequestId     string `description:"云API参数:RequestId,请求句柄,默认都会传给后端,方便定位问题"`
	Action        string `v:"required" description:"云API参数:API接口名称,默认都会传给后端,提供后端业务区分接口,从而保持内外接口名称一致。"`
	Uin           string `description:"云API参数:资源拥有者(主账号)UIN"`
	SubAccountUin string `description:"云API参数:请求者自身(子账号/协作者/角色)uin。UIN SubAccountUin 模式"`
	ClientIp      string `description:"云API参数:客户端来源IP"`
	ApiModule     string `description:"云API参数:被请求的模块名"`
	Region        string `description:"云API参数:地域英文Id"`
	Token         string `description:"云API参数:临时证书Token"`
	Version       string `description:"云API参数:版本"`
	RequestSource string `description:"云API参数:请求来源,目前仅区分MC和API"`
	Language      string `description:"云API参数:语言信息,目前取值:zh-CN和en-US。不同语言返回的错误Message不一样,目前仅cvm业务支持。"`
	Timestamp     string `description:"云API参数:当前时间戳,来自公共请求参数"`
}

type DeleteInstanceRiskReq struct {
	g.Meta     `path:"/DeleteInstanceRisk" tags:"实例风险管理" method:"post" summary:"删除实例风险"`
	InstanceId string `v:"required" dc:"实例ID"`
	Type       string `v:"required" dc:"风险类型"`
}

I set QCloudV3CommonReq to openapi.Config.CommonRequest.

What did you see happen?

image Request parameter constraints in `QCloudV3CommonReq` are displayed normally, but `DeleteInstanceRiskReq` misses the constraints.

What did you expect to see?

Request parameter constraints in DeleteInstanceRiskReq can be displayed normally.

jswxstw avatar May 24 '24 09:05 jswxstw

what is QCloudV3CommonRes?

Is it like this?

type QCloudV3CommonRes struct{
	DeleteInstanceRiskReq
	QCloudV3CommonReq
}

I don't know how to reproduce it, can you provide the min reproduction code?

wufeng5702 avatar Jul 29 '24 11:07 wufeng5702

@niluan304 Thank you for looking at this. CommonResponse does not matter, you can test the difference between CommonRequest is set or not set:

func (c *cMain) enhanceOpenAPIDoc(s *ghttp.Server) {
	openapi := s.GetOpenApi()
        // CommonRequest is set to QCloudV3CommonReq.
	openapi.Config.CommonRequest = QCloudV3CommonReq{}
}

jswxstw avatar Jul 30 '24 04:07 jswxstw