diff --git a/src/Directory.Build.props b/src/Directory.Build.props index cd562db..7ac75f4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -17,7 +17,7 @@ https://github.com/benmccallum/fairybread/raw/master/logo-400x400.png https://github.com/benmccallum/fairybread/blob/master/LICENSE - 6.0.1 + 6.1.0 11.0.9 diff --git a/src/FairyBread/DefaultFairyBreadOptions.cs b/src/FairyBread/DefaultFairyBreadOptions.cs index 51d4c97..4ad48d1 100644 --- a/src/FairyBread/DefaultFairyBreadOptions.cs +++ b/src/FairyBread/DefaultFairyBreadOptions.cs @@ -10,6 +10,9 @@ public class DefaultFairyBreadOptions : IFairyBreadOptions { public virtual bool ThrowIfNoValidatorsFound { get; set; } = true; + /// + public virtual bool SetNullResultOnValidationError { get; set; } = true; + /// public virtual Func ShouldValidate { get; set; } = DefaultImplementations.ShouldValidate; diff --git a/src/FairyBread/IFairyBreadOptions.cs b/src/FairyBread/IFairyBreadOptions.cs index f87c3d6..dfaef72 100644 --- a/src/FairyBread/IFairyBreadOptions.cs +++ b/src/FairyBread/IFairyBreadOptions.cs @@ -13,6 +13,12 @@ public interface IFairyBreadOptions /// bool ThrowIfNoValidatorsFound { get; set; } + /// + /// If true, FairyBread will set the current field's IResolverContext.Result + /// to null when a validation error occurs. + /// + bool SetNullResultOnValidationError { get; set; } + /// /// Function used to determine if an argument should be validated by /// FairyBread's . diff --git a/src/FairyBread/InputValidationMiddleware.cs b/src/FairyBread/InputValidationMiddleware.cs index 179208e..8b75154 100644 --- a/src/FairyBread/InputValidationMiddleware.cs +++ b/src/FairyBread/InputValidationMiddleware.cs @@ -76,7 +76,11 @@ public async Task InvokeAsync(IMiddlewareContext context) if (invalidResults.Any()) { _validationErrorsHandler.Handle(context, invalidResults); - context.Result = null; + + if (_options.SetNullResultOnValidationError) + { + context.Result = null; + } } else {