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

fix unvalidated entries when validation is skipped due to annotation configuration #18

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup>
<PackageVersion>1.3.0</PackageVersion>
<PackageVersion>1.3.1</PackageVersion>
<Company>SharpGrip</Company>
<Authors>SharpGrip</Authors>
<Copyright>SharpGrip</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
this.autoValidationMvcConfiguration = autoValidationMvcConfiguration.Value;
}

public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)

Check warning on line 34 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 34 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 34 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 34 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 34 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (context.Controller is ControllerBase controllerBase)
{
Expand All @@ -41,6 +41,8 @@
if (autoValidationMvcConfiguration.ValidationStrategy == ValidationStrategy.Annotations &&
endpoint != null && !endpoint.Metadata.OfType<FluentValidationAutoValidationAttribute>().Any())
{
HandleUnvalidatedEntries(context);

await next();

return;
Expand All @@ -60,7 +62,7 @@
(autoValidationMvcConfiguration.EnablePathBindingSourceAutomaticValidation && bindingSource == BindingSource.Path) ||
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom)))
{
if (serviceProvider.GetValidator(parameterType) is IValidator validator)

Check warning on line 65 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)

Check warning on line 65 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)

Check warning on line 65 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)

Check warning on line 65 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)

Check warning on line 65 in FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

View workflow job for this annotation

GitHub Actions / build

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)
{
var validationResult = await validator.ValidateAsync(new ValidationContext<object>(subject), context.HttpContext.RequestAborted);

Expand All @@ -76,13 +78,7 @@
}
}

if (autoValidationMvcConfiguration.DisableBuiltInModelValidation)
{
foreach (var modelStateEntry in context.ModelState.Values.Where(modelStateEntry => modelStateEntry.ValidationState == ModelValidationState.Unvalidated))
{
modelStateEntry.ValidationState = ModelValidationState.Skipped;
}
}
HandleUnvalidatedEntries(context);

if (!context.ModelState.IsValid)
{
Expand All @@ -96,5 +92,16 @@

await next();
}

private void HandleUnvalidatedEntries(ActionExecutingContext context)
{
if (autoValidationMvcConfiguration.DisableBuiltInModelValidation)
{
foreach (var modelStateEntry in context.ModelState.Values.Where(modelStateEntry => modelStateEntry.ValidationState == ModelValidationState.Unvalidated))
{
modelStateEntry.ValidationState = ModelValidationState.Skipped;
}
}
}
}
}