Skip to content

Commit 82d6cfc

Browse files
Introduce support for headers automatic validation (#65)
1 parent a9c5045 commit 82d6cfc

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

FluentValidation.AutoValidation.Mvc/src/Configuration/AutoValidationMvcConfiguration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class AutoValidationMvcConfiguration
4444
/// <see cref="FromRouteAttribute"/>
4545
public bool EnablePathBindingSourceAutomaticValidation { get; set; } = false;
4646

47+
/// <summary>
48+
/// Enables asynchronous automatic validation for parameters bound from <see cref="BindingSource.Header"/> binding sources (typically parameters decorated with the [FromHeader] attribute).
49+
/// </summary>
50+
/// <see cref="FromHeaderAttribute"/>
51+
public bool EnableHeaderBindingSourceAutomaticValidation { get; set; } = false;
52+
4753
/// <summary>
4854
/// Enables asynchronous automatic validation for parameters bound from <see cref="BindingSource.Custom"/> binding sources.
4955
/// </summary>

FluentValidation.AutoValidation.Mvc/src/Filters/FluentValidationAutoValidationActionFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ private bool HasValidBindingSource(BindingSource? bindingSource)
141141
(autoValidationMvcConfiguration.EnableFormBindingSourceAutomaticValidation && bindingSource == BindingSource.Form) ||
142142
(autoValidationMvcConfiguration.EnableQueryBindingSourceAutomaticValidation && bindingSource == BindingSource.Query) ||
143143
(autoValidationMvcConfiguration.EnablePathBindingSourceAutomaticValidation && bindingSource == BindingSource.Path) ||
144+
(autoValidationMvcConfiguration.EnableHeaderBindingSourceAutomaticValidation && bindingSource == BindingSource.Header) ||
144145
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom) ||
145146
(autoValidationMvcConfiguration.EnableNullBindingSourceAutomaticValidation && bindingSource == null);
146147
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ app.MapPost("/", (SomeOtherModel someOtherModel) => $"Hello again {someOtherMode
8080
| EnableFormBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Form` binding sources (typically parameters decorated with the `[FromForm]` attribute). |
8181
| EnableQueryBindingSourceAutomaticValidation | `true` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Query` binding sources (typically parameters decorated with the `[FromQuery]` attribute). |
8282
| EnablePathBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Path` binding sources (typically parameters decorated with the `[FromRoute]` attribute). |
83+
| EnableHeaderBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Header` binding sources (typically parameters decorated with the `[FromHeader]` attribute). |
8384
| EnableCustomBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Custom` binding sources. |
8485
| EnableNullBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters not bound from any binding source (typically parameters without a declared or inferred binding source). |
8586

0 commit comments

Comments
 (0)