Skip to content

add null binding source #43

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class AutoValidationMvcConfiguration
/// </summary>
public bool EnableCustomBindingSourceAutomaticValidation { get; set; } = false;

/// <summary>
/// Enables asynchronous automatic validation for parameters not bound from any binding source (typically parameters without a declared or inferred binding source).
/// </summary>
public bool EnableNullBindingSourceAutomaticValidation { get; set; } = false;

/// <summary>
/// Holds the overridden result factory. This property is meant for infrastructure and should not be used by application code.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
this.autoValidationMvcConfiguration = autoValidationMvcConfiguration.Value;
}

public async Task OnActionExecutionAsync(ActionExecutingContext actionExecutingContext, ActionExecutionDelegate next)

Check warning on line 33 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 50 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

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

View workflow job for this annotation

GitHub Actions / build

Rename parameter 'actionExecutingContext' to 'context' to match the interface declaration. (https://rules.sonarsource.com/csharp/RSPEC-927)

Check warning on line 33 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 50 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (IsValidController(actionExecutingContext.Controller))
{
Expand All @@ -40,7 +40,7 @@

if (endpoint != null &&
((autoValidationMvcConfiguration.ValidationStrategy == ValidationStrategy.Annotations &&
!endpoint.Metadata.OfType<FluentValidationAutoValidationAttribute>().Any() && !endpoint.Metadata.OfType<AutoValidationAttribute>().Any()) ||

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

View workflow job for this annotation

GitHub Actions / build

'FluentValidationAutoValidationAttribute' is obsolete: 'Attribute is obsolete and will be removed in v2. Use the

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

View workflow job for this annotation

GitHub Actions / build

'FluentValidationAutoValidationAttribute' is obsolete: 'Attribute is obsolete and will be removed in v2. Use the
endpoint.Metadata.OfType<AutoValidateNeverAttribute>().Any()))
{
HandleUnvalidatedEntries(actionExecutingContext);
Expand Down Expand Up @@ -120,7 +120,7 @@
await next();
}

private bool IsValidController(object controller)

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

View workflow job for this annotation

GitHub Actions / build

Make 'IsValidController' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
var controllerType = controller.GetType();

Expand All @@ -141,7 +141,8 @@
(autoValidationMvcConfiguration.EnableFormBindingSourceAutomaticValidation && bindingSource == BindingSource.Form) ||
(autoValidationMvcConfiguration.EnableQueryBindingSourceAutomaticValidation && bindingSource == BindingSource.Query) ||
(autoValidationMvcConfiguration.EnablePathBindingSourceAutomaticValidation && bindingSource == BindingSource.Path) ||
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom);
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom) ||
(autoValidationMvcConfiguration.EnableNullBindingSourceAutomaticValidation && bindingSource == null);
}

private void HandleUnvalidatedEntries(ActionExecutingContext context)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ app.MapPost("/", (SomeOtherModel someOtherModel) => $"Hello again {someOtherMode
| EnableQueryBindingSourceAutomaticValidation | `true` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Query` binding sources (typically parameters decorated with the `[FromQuery]` attribute). |
| EnablePathBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Path` binding sources (typically parameters decorated with the `[FromRoute]` attribute). |
| EnableCustomBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Custom` binding sources. |
| EnableNullBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters not bound from any binding source (typically parameters without a declared or inferred binding source). |

```
using SharpGrip.FluentValidation.AutoValidation.Mvc.Extensions;
Expand Down
Loading