规范路由注册时,参数设置为 in:"header",生成api.json正常(有header参数),但是调用接口时框架无法解析这个参数
1. What version of Go and system type/arch are you using?
go version go1.17.1 windows/amd64
2. What version of GoFrame are you using?
v2.1.1
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
// 在header中传 AppKey 参数
type QueryReq struct {
g.Meta `path:"/query" tags:"查询" method:"post" summary:"查询"`
AppKey string `in:"header" v:"required#业务系统唯一码不能为空"`
}
5. What did you expect to see?
正常解析参数
6. What did you see instead?
业务系统唯一码不能为空
能否提供最小代码
package main
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type QueryReq struct {
g.Meta `path:"/query" tags:"查询" method:"post" summary:"查询"`
AppKey string `in:"header" v:"required#业务系统唯一码不能为空"`
}
type QueryRes struct {
}
type Controller struct{}
var c Controller
func (a *Controller) Index(ctx context.Context, req *QueryReq) (res *QueryRes, err error) {
g.Log().Info(ctx, req)
return
}
func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(c)
})
s.SetPort(8199)
s.Run()
}
@mingzaily
跟 #2036 的问题一样
和社区小伙伴讨论了下,文档中的in只是给openapi的展示,解析参数并未支持,后续会添加功能
假如现在需要从header中取数据,可以现在先这样
r := g.RequestFromCtx(ctx)
r.GetHeader("AppKey")
或使用中间件处理
目前还没进到 Index 方法就 error 了
可以使用中间件或先取消header参数的必传验证
计划分几步操作
- [x] 1. 先实现一版直接反射的,但效率不高
- [x] 2. 配套单元测试
- [ ] 3. 在注册路由时进行反射解析缓存起来,提高请求时的处理效率
- [ ] 默认值
- [ ] 数据校验
- [ ] 规范路由
- [ ] 其它tag
@sanrentai 目前已经支持了
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@sanrentai is currently supported