-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from appany/0.1.12
Move attemptedValues to extended details
- Loading branch information
Showing
41 changed files
with
1,548 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Attribute-based approach | ||
|
||
Use default input validator | ||
|
||
```cs | ||
... Example([UseFluentValidation] ExampleInput input) { ... } | ||
``` | ||
|
||
Use single validator type for single validator | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseValidator(typeof(ExampleInputValidator))] ExampleInput input) { ... } | ||
``` | ||
|
||
Use single validator type for multiple validators | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseValidators(typeof(IValidator<ExampleInput>))] ExampleInput input) { ... } | ||
``` | ||
|
||
Use validator with custom [validation strategy](validation-strategies.md) | ||
|
||
```cs | ||
... Example([ | ||
UseFluentValidation, | ||
UseValidator( | ||
typeof(ExampleInputValidator), | ||
IncludeProperties=new[]{"ExampleProperty"}, | ||
IncludeRuleSets=new[]{"FastValidation"}) | ||
] ExampleInput input) { ... } | ||
``` | ||
|
||
Use validators with custom [validation strategy](validation-strategies.md) | ||
|
||
```cs | ||
... Example([ | ||
UseFluentValidation, | ||
UseValidators( | ||
typeof(ExampleInputValidator), | ||
IncludeAllRuleSets=true, | ||
IncludeRulesNotInRuleSet=true) | ||
] ExampleInput input) { ... } | ||
``` | ||
|
||
Use default [input validator](input-validators.md) | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseDefaultInputValidator)] ExampleInput input) { ... } | ||
``` | ||
|
||
Use default [error mapper](error-mappers.md) | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseDefaultErrorMapper)] ExampleInput input) { ... } | ||
``` | ||
|
||
Use default [error mapper](error-mappers.md) with details | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseDefaultErrorMapperWithDetails)] ExampleInput input) { ... } | ||
``` | ||
|
||
Use default [error mapper](error-mappers.md) with extended details | ||
|
||
```cs | ||
... Example([UseFluentValidation, UseDefaultErrorMapperWithExtendedDetails)] ExampleInput input) { ... } | ||
``` | ||
|
||
Skip validation | ||
|
||
```cs | ||
... Example([UseFluentValidation, SkipValidation)] ExampleInput input) { ... } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using FluentValidation.Internal; | ||
|
||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public abstract class BaseUseValidatorAttribute : FluentValidationAttribute | ||
{ | ||
protected BaseUseValidatorAttribute(Type validatorType) | ||
{ | ||
ValidatorType = validatorType; | ||
} | ||
|
||
public Type ValidatorType { get; } | ||
|
||
public string[]? IncludeProperties { get; set; } | ||
public string[]? IncludeRuleSets { get; set; } | ||
public bool IncludeAllRuleSets { get; set; } | ||
public bool IncludeRulesNotInRuleSet { get; set; } | ||
|
||
protected Action<ValidationStrategy<object>>? TryGetValidationStrategy() | ||
{ | ||
var shouldUseValidationStrategy = IncludeProperties is not null | ||
|| IncludeRuleSets is not null | ||
|| IncludeAllRuleSets | ||
|| IncludeRulesNotInRuleSet; | ||
|
||
if (shouldUseValidationStrategy) | ||
{ | ||
return strategy => | ||
{ | ||
if (IncludeProperties is not null) | ||
{ | ||
strategy.IncludeProperties(IncludeProperties); | ||
} | ||
|
||
if (IncludeRuleSets is not null) | ||
{ | ||
strategy.IncludeRuleSets(IncludeRuleSets); | ||
} | ||
|
||
if (IncludeAllRuleSets) | ||
{ | ||
strategy.IncludeAllRuleSets(); | ||
} | ||
|
||
if (IncludeRulesNotInRuleSet) | ||
{ | ||
strategy.IncludeRulesNotInRuleSet(); | ||
} | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public abstract class FluentValidationAttribute : Attribute | ||
{ | ||
public abstract void Configure(ArgumentValidationBuilder builder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class SkipValidationAttribute : FluentValidationAttribute | ||
{ | ||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
builder.SkipValidation(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseDefaultErrorMapperAttribute : FluentValidationAttribute | ||
{ | ||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
builder.UseDefaultErrorMapper(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Attributes/UseDefaultErrorMapperWithDetailsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseDefaultErrorMapperWithDetailsAttribute : FluentValidationAttribute | ||
{ | ||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
builder.UseDefaultErrorMapperWithDetails(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Attributes/UseDefaultErrorMapperWithExtendedDetailsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseDefaultErrorMapperWithExtendedDetailsAttribute : FluentValidationAttribute | ||
{ | ||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
builder.UseDefaultErrorMapperWithExtendedDetails(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseDefaultInputValidatorAttribute : FluentValidationAttribute | ||
{ | ||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
builder.UseDefaultInputValidator(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseValidatorAttribute : BaseUseValidatorAttribute | ||
{ | ||
public UseValidatorAttribute(Type validatorType) | ||
: base(validatorType) | ||
{ | ||
} | ||
|
||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
var validationStrategy = TryGetValidationStrategy(); | ||
|
||
if (validationStrategy is null) | ||
{ | ||
builder.UseValidator(ValidatorType); | ||
} | ||
else | ||
{ | ||
builder.UseValidator(ValidatorType, validationStrategy); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace AppAny.HotChocolate.FluentValidation | ||
{ | ||
public sealed class UseValidatorsAttribute : BaseUseValidatorAttribute | ||
{ | ||
public UseValidatorsAttribute(Type validatorType) | ||
: base(validatorType) | ||
{ | ||
} | ||
|
||
public override void Configure(ArgumentValidationBuilder builder) | ||
{ | ||
var validationStrategy = TryGetValidationStrategy(); | ||
|
||
if (validationStrategy is null) | ||
{ | ||
builder.UseValidators(ValidatorType); | ||
} | ||
else | ||
{ | ||
builder.UseValidators(ValidatorType, validationStrategy); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.