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

Request validator tag "required-if" is invalid #3484

Open
fainc opened this issue Apr 12, 2024 · 7 comments
Open

Request validator tag "required-if" is invalid #3484

fainc opened this issue Apr 12, 2024 · 7 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@fainc
Copy link
Contributor

fainc commented Apr 12, 2024

Get http://127.0.0.1:8002/workspace/district/list/level?page=1 // ⚠️no xx field

type DistrictListReq struct {
	g.Meta     `path:"/district/list/{method}" tags:"District" method:"get" summary:"获取行政区划"`
	Method     string `json:"method" v:"required|in:pid,pcode,level"`
	Page       int    `json:"page" v:"required|min:0"`
	Xx      int    `json:"xx" v:"required-if:method,level|min:0"`//  it's work ✅  tips "The Xx field is required"
        Xx      int    `json:"xx" v:"min:0|required-if:method,level"`//  it's not work ⚠️ request into controller 
}

Go Version: go1.20.8
GF Version: v2.6.4

@fainc fainc added the bug It is confirmed a bug, but don't worry, we'll handle it. label Apr 12, 2024
@fainc
Copy link
Contributor Author

fainc commented Apr 12, 2024

required-if 规则在 min 规则之后时 required 失效 不传递参数也能验证通过;在min规则之前则正常

@Issues-translate-bot
Copy link

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


When the required-if rule is after the min rule, required is invalid and the verification can pass without passing parameters; it is normal before the min rule.

@wln32
Copy link
Member

wln32 commented Apr 18, 2024

@fainc @gqcn
当这样定义验证的规则的时候,由于没有Xx参数,所以required-if验证规则会不通过,返回"The Xx field is required"
Xx int json:"xx" v:"required-if:method,level|min:0"

但是如果反过来,验证min规则其实是没有通过的,返回了错误
但是由于不是required系列的规则,直接跳出了循环
没有设置errorMaps变量

函数的路径:gogf\gf\[email protected]\util\gvalid\gvalid_validator_check_struct.go

1

@fainc
Copy link
Contributor Author

fainc commented May 16, 2024

@wln32 搞一下?

@Issues-translate-bot
Copy link

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


@wln32 Do it?

@wln32
Copy link
Member

wln32 commented May 16, 2024

@wln32 搞一下?

@fainc 搞不了,验证那块的代码一堆if判断,你可以尝试在我分析出来的那块代码加个if判断试试,看看能不能满足你想要的结果

@Issues-translate-bot
Copy link

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


@wln32 Do it?

@fainc I can’t do it. The verification code contains a lot of if judgments. You can try adding an if judgment to the code I analyzed to see if it can satisfy the result you want.

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

No branches or pull requests

3 participants