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

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

Open
jswxstw opened this issue May 24, 2024 · 2 comments · May be fixed by #3724
Open

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

jswxstw opened this issue May 24, 2024 · 2 comments · May be fixed by #3724
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@jswxstw
Copy link
Contributor

jswxstw commented May 24, 2024

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 jswxstw added the bug It is confirmed a bug, but don't worry, we'll handle it. label May 24, 2024
@niluan304
Copy link
Contributor

niluan304 commented Jul 29, 2024

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?

@jswxstw
Copy link
Contributor Author

jswxstw commented Jul 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants