10000 Validation: add WithMessage by System-Glitch · Pull Request #260 · go-goyave/goyave · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Validation: add WithMessage #260

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 9, 2025
Merged

Conversation

System-Glitch
Copy link
Member
@System-Glitch System-Glitch commented Apr 7, 2025

References

Issue(s): closes #250

Description

  • Added validation.WithMessage() function, which overrides the language entry used to render the error message of a validator.
    • Original placeholders returned by the validator are still used to render the message.
    • Type-dependent and "element" suffixes are not added when the message is overridden.

Example usage:

func (ctrl *Controller) UpdateRequest(_ *goyave.Request) v.RuleSet {
	return v.RuleSet{
		//...
		{Path: "contents", Rules: v.List{v.WithMessage(v.String(), "validation.rules.custom"), v.Min(10)}},
	}
}

Possible drawbacks

The WithMessage syntax is not the cleanest. However, using a method instead wouldn't be possible because it would need to return itself, which wouldn't be possible with composition.

@System-Glitch System-Glitch added the feature request Request for new feature implementation label Apr 7, 2025
@System-Glitch System-Glitch force-pushed the feat/validator-override-message branch from 53a8a3c to 4a74658 Compare April 7, 2025 14:58
@System-Glitch System-Glitch self-assigned this Apr 7, 2025
@System-Glitch System-Glitch added this to the v5.6.0 milestone Apr 7, 2025
@coveralls
Copy link
coveralls commented Apr 7, 2025

Pull Request Test Coverage Report for Build 14337030354

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 97.516%

Totals Coverage Status
Change from base Build 14337018348: 0.005%
Covered Lines: 6477
Relevant Lines: 6642

💛 - Coveralls

@System-Glitch System-Glitch force-pushed the feat/validator-override-message branch from 4a74658 to 79afaeb Compare April 8, 2025 15:06
@System-Glitch System-Glitch merged commit b596ffc into master Apr 9, 2025
10 checks passed
@System-Glitch System-Glitch deleted the feat/validator-override-message branch April 9, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new feature implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation: override message
2 participants
0