-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Recursive validation replaced by attribute. Fixes stackoverflow …
…issue
- Loading branch information
Showing
12 changed files
with
82 additions
and
80 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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Zeus.Shared.Validation; | ||
|
||
namespace Zeus.Features.Alerting.Channels | ||
{ | ||
public class ChannelsOptions | ||
{ | ||
[Required] | ||
[Required, ValidateObject] | ||
public ChannelsStoreOptions Store { get; set; } | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Zeus/Features/Alerting/Subscriptions/SubscriptionsOptions.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Zeus.Shared.Validation; | ||
|
||
namespace Zeus.Features.Alerting.Subscriptions | ||
{ | ||
public class SubscriptionsOptions | ||
{ | ||
[Required] | ||
[Required, ValidateObject] | ||
public SubscriptionsStoreOptions Store { get; set; } | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
src/Zeus/Features/Alerting/Subscriptions/SubscriptionsStoreOptions.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
namespace Zeus.Features.Alerting.Subscriptions | ||
using Zeus.Shared.Validation; | ||
|
||
namespace Zeus.Features.Alerting.Subscriptions | ||
{ | ||
public class SubscriptionsStoreOptions | ||
{ | ||
public bool UseInMemoryStore { get; set; } | ||
|
||
[ValidateObject] | ||
public SubscriptionsConsulStoreOptions Consul { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Zeus.Shared.Validation; | ||
|
||
namespace Zeus.Features.Alerting.Templates | ||
{ | ||
public class TemplatesOptions | ||
{ | ||
[Required] | ||
[Required, ValidateObject] | ||
public TemplatesStoreOptions Store { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Zeus.Shared.Validation; | ||
|
||
namespace Zeus.Features.Alerting.Templates | ||
{ | ||
public class TemplatesStoreOptions | ||
{ | ||
[Required] | ||
[Required, ValidateObject] | ||
public TemplatesFileSystemStoreOptions FileSystem { get; set; } | ||
} | ||
} |
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
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,20 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Zeus.Shared.Validation | ||
{ | ||
internal class CompositeValidationResult : ValidationResult | ||
{ | ||
public CompositeValidationResult(string errorMessage) | ||
: base(errorMessage) { } | ||
|
||
public CompositeValidationResult(string errorMessage, IEnumerable<string> memberNames) | ||
: base(errorMessage, memberNames) { } | ||
|
||
protected CompositeValidationResult(ValidationResult validationResult) | ||
: base(validationResult) { } | ||
|
||
public List<ValidationResult> InnerResults { get; } | ||
= new List<ValidationResult>(); | ||
} | ||
} |
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,28 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Zeus.Shared.Validation | ||
{ | ||
public class ValidateObjectAttribute : ValidationAttribute | ||
{ | ||
protected override ValidationResult IsValid(object value, ValidationContext validationContext) | ||
{ | ||
if (value == null) | ||
return ValidationResult.Success; | ||
|
||
var results = new List<ValidationResult>(); | ||
var context = new ValidationContext(value, null, null); | ||
|
||
var isValid = Validator.TryValidateObject(value, context, results, true); | ||
if (isValid) | ||
return ValidationResult.Success; | ||
|
||
var compositeResults = | ||
new CompositeValidationResult($"Validation for {validationContext.DisplayName} failed"); | ||
|
||
compositeResults.InnerResults.AddRange(results); | ||
|
||
return compositeResults; | ||
} | ||
} | ||
} |