Skip to content

fix: prioritize custom validator #1316

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

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

FGYFFFF
Copy link
Contributor

@FGYFFFF FGYFFFF commented Mar 27, 2025

fixes #1314

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):
之前的设计是 Binder 和 Validator 是两个独立的组件,Binder 拥有自己的 Validator,配合进行 ctx.bindAndValidate();而 binder 只作用于 ctx.Validate()。

根据用户反馈这么做有些反直觉,因此将这个配置做一个优化,如果用户自定义了 Validator (包括修改配置和设置自定义 Validator),那么Binder 就优先使用这个自定义的 Validator。

(Optional) Which issue(s) this PR fixes:

(Optional) The PR that updates user documentation:

@FGYFFFF FGYFFFF requested review from a team as code owners March 27, 2025 13:23
Copy link

codecov bot commented Mar 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.80%. Comparing base (67fe3c7) to head (28eb582).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1316      +/-   ##
===========================================
- Coverage    72.80%   72.80%   -0.01%     
===========================================
  Files          139      139              
  Lines        16244    16247       +3     
===========================================
+ Hits         11826    11828       +2     
- Misses        3823     3824       +1     
  Partials       595      595              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -607,6 +610,10 @@ func (engine *Engine) initBinderAndValidator(opt *config.Options) {
if !ok {
panic("opt.BindConfig is not the '*binding.BindConfig' type")
}
// optimize: user customized validator has the highest priority
if isCustomValidator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isCustomValidator || bConf.Validator == nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@FGYFFFF FGYFFFF force-pushed the feat/optimize_validate_cfg branch 2 times, most recently from 2067fa2 to 2275077 Compare March 28, 2025 06:22
@xiaost xiaost changed the title feat: optimze validate config, custom validator has highest priority fix: prioritize custom validator Apr 14, 2025
@xiaost xiaost force-pushed the feat/optimize_validate_cfg branch from 2275077 to 28eb582 Compare April 14, 2025 07:59
@xiaost xiaost merged commit 530693a into cloudwego:develop Apr 14, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

SetValidatorErrorFactory无效
3 participants