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

When the API parameter setting in tag is header, the field configuration custom header key is invalid. #3245

Closed
shuqingzai opened this issue Jan 4, 2024 · 0 comments · Fixed by #3298
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@shuqingzai
Copy link

使用下面的示例代码,分别打开 HeaderName 的 3 个 case 测试

package main

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

type HelloReq struct {
	g.Meta `path:"/hello" method:"get"`
	Name   string `json:"name" v:"required" dc:"Your name"`
	// 1. 指定 json 标签 header key -- 无效
	// 字段名: HeaderName Header传递的key: X-Header-Name
	// HeaderName string `json:"X-Header-Name" in:"header" v:"required" dc:"Your Header name"`
	// 2. 字段名: HeaderName 指定 p 标签 header key -- 无效
	// 字段名: HeaderName Header传递的key: X-Header-Name
	// HeaderName string `p:"X-Header-Name" in:"header" json:"X-Header-Name" v:"required" dc:"Your Header name"`
	// 3. 只有 字段名 与 header key 相同(PascalCase ==> kebab-case)才有效 -- 有效
	// 字段名: XHeaderName Header传递的key: X-Header-Name
	XHeaderName string `in:"header" json:"X-Header-Name" v:"required" dc:"Your Header name"`
}
type HelloRes struct {
	Reply any
}

type Hello struct{}

func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
	g.Log().Debugf(ctx, `receive say: %+v`, req)
	res = &HelloRes{
		Reply: req,
	}
	return
}

func main() {
	s := g.Server()
	s.SetPort(8800)
	s.Use(ghttp.MiddlewareHandlerResponse)
	s.Group("/", func(group *ghttp.RouterGroup) {
		group.Bind(
			new(Hello),
		)
	})
	s.Run()
}

测试代码

curl --location --request GET 'http://127.0.0.1:8800/hello?name=test' \
--header 'X-Header-Name: test header' \
--header 'User-Agent: GF-API-TESTTING' \
--header 'Accept: */*' \
--header 'Host: 127.0.0.1:8800' \
--header 'Connection: keep-alive'

根据文档所说可以使用 p 标签设置字段名称,但是似乎在 header key 中无效,仅在请求参数有效
参考:请求输入请求校验#示例1,基本使用

What version of Go and system type/arch are you using?

#-> % go version
go version go1.21.5 darwin/amd64

What version of GoFrame are you using?

-> % gf --version
v2.6.1
Welcome to GoFrame!
Env Detail:
  Go Version: go1.21.5 darwin/amd64
  GF Version(go.mod):
    github.com/gogf/gf/[email protected]
CLI Detail:
  Installed At: /Users/Code/go/bin/gf
  Built Go Version: go1.21.5
  Built GF Version: v2.6.1
Others Detail:
  Docs: https://goframe.org
  Now : 2024-01-03T16:01:15+08:00

Can this bug be re-produced with the latest release?

YES

What did you do?

What did you expect to see?

What did you see instead?

@shuqingzai shuqingzai added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jan 4, 2024
@Issues-translate-bot Issues-translate-bot changed the title API参数设置 in 标签为 header 时,字段配置自定义header key无效 When the API parameter setting in label is header, the field configuration custom header key is invalid. Jan 4, 2024
@shuqingzai shuqingzai changed the title When the API parameter setting in label is header, the field configuration custom header key is invalid. When the API parameter setting in tag is header, the field configuration custom header key is invalid. Jan 4, 2024
@oldme-git oldme-git self-assigned this Feb 1, 2024
@oldme-git oldme-git mentioned this issue Feb 2, 2024
oldme-git added a commit to oldme-git/gf that referenced this issue Feb 2, 2024
# Conflicts:
#	net/ghttp/ghttp_z_unit_issue_test.go
oldme-git added a commit to oldme-git/gf that referenced this issue Feb 5, 2024
@gqcn gqcn closed this as completed in #3298 Feb 6, 2024
gqcn pushed a commit that referenced this issue Feb 6, 2024
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