ValidationFailure should be aware of it's RuleSet
See original GitHub issueIs your feature request related to a problem? Please describe.
When a ValidationFailure
is constructed, it should be aware of the RuleSet name that it came from.
Describe the solution you’d like
Please add the following to ValidationFailure
public string RuleSet { get; }
Describe alternatives you’ve considered I’ve attempted to foreach all of my rulesets, but unfortunately I don’t even see the validation failure when I do this.
var failures = new Dictionary<string, ValidationResult>();
foreach (var ruleSet in _ruleSets)
{
var result = await _validator.ValidateAsync(self, opts => opts.IncludeRuleSets(ruleSet));
failures[ruleSet] = result; // unfortunately this is always IsValid = true;
isValid = isValid && result.Errors.All(x => x.Severity != Severity.Error);
}
Additional context Effectively I need to emit out validation failures based on the grouping of validation. In other words, a particular segment of my overall object can be valid or invalid based on a RuleSet.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Set a message for a RuleSet fails in FluentValidation
SIMPLE SOLUTION. It is impossible to set error message to RuleSet directly without changing FluentValidation sources, but you can collect ...
Read more >Setting the Severity Level
By default, if these rules fail they will have a severity of Error . This can be changed by calling the WithSeverity method....
Read more >Rule Set prerequisite based validation
Rule Set prerequisite based validation ... This example uses a mixture of AV mode and Rule Validation (RV) mode. A ruleset name with...
Read more >Validating data quality in AWS Glue DataBrew
A validation failure for that ruleset might mean that the data isn't acceptable for further use. An example is missing values in key...
Read more >How to use FluentValidation in ASP.NET Core Apps (.Net 6)
FluentValidation is a popular .NET library for building strongly-typed validation rules in applications. Learn how to use FluentValidation ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ChaseFlorell Yes that’s correct, custom state is always per-validator, it’s not shared between the whole rule chain. However you can add an extension method that would apply it the whole chain quite easily:
Then you can call:
It must be the last method in the chain, as it’ll only apply to any validators that precede it.
An individual rule can actually be part of multiple rulesets, so this will probably be an array of strings rather than a single string.