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

need tag in:header works in router definition #2060

Closed
sanrentai opened this issue Aug 10, 2022 · 10 comments
Closed

need tag in:header works in router definition #2060

sanrentai opened this issue Aug 10, 2022 · 10 comments
Assignees
Labels
planned This issue/proposal is planned into our next steps.

Comments

@sanrentai
Copy link
Contributor

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?

业务系统唯一码不能为空

@mingzaily
Copy link
Member

能否提供最小代码

@sanrentai
Copy link
Contributor Author

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()
}

image
@mingzaily

@sanrentai
Copy link
Contributor Author

#2036 的问题一样

@mingzaily mingzaily added bug It is confirmed a bug, but don't worry, we'll handle it. feature and removed bug It is confirmed a bug, but don't worry, we'll handle it. labels Aug 12, 2022
@mingzaily
Copy link
Member

mingzaily commented Aug 12, 2022

和社区小伙伴讨论了下,文档中的in只是给openapi的展示,解析参数并未支持,后续会添加功能

@mingzaily
Copy link
Member

假如现在需要从header中取数据,可以现在先这样

r := g.RequestFromCtx(ctx)
r.GetHeader("AppKey")

或使用中间件处理

@sanrentai
Copy link
Contributor Author

目前还没进到 Index 方法就 error 了

@mingzaily
Copy link
Member

可以使用中间件或先取消header参数的必传验证

@gqcn gqcn added planned This issue/proposal is planned into our next steps. and removed feature inactive labels Jan 18, 2023
@hailaz hailaz self-assigned this Feb 16, 2023
@hailaz
Copy link
Member

hailaz commented Feb 16, 2023

计划分几步操作

  • 1. 先实现一版直接反射的,但效率不高
  • 2. 配套单元测试
  • 3. 在注册路由时进行反射解析缓存起来,提高请求时的处理效率
    • 默认值
    • 数据校验
    • 规范路由
    • 其它tag

@gqcn gqcn changed the title 规范路由注册时,参数设置为 in:"header",生成api.json正常(有header参数),但是调用接口时框架无法解析这个参数 need tag in:header works in router definition Mar 7, 2023
@hailaz
Copy link
Member

hailaz commented Mar 14, 2023

@sanrentai 目前已经支持了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@sanrentai is currently supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

5 participants