Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fluentvalidation for child properties
- Loading branch information
Thomas Brenna
committed
Mar 12, 2024
1 parent
4589036
commit d9e5357
Showing
5 changed files
with
50 additions
and
23 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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
using ServiceStack; | ||
|
||
using ServiceStack.FluentValidation; | ||
using ServiceStack.FluentValidation.Results; | ||
using System.Collections.Generic; | ||
|
||
namespace testss.ServiceModel; | ||
|
||
[Route("/list")] | ||
public class MyListRequest : IPost, IReturn<MyListResponse> | ||
{ | ||
public required List<ListEntry> Entries { get; set; } | ||
} | ||
|
||
public class MyListResponse | ||
{ | ||
public required List<string> Result { get; set; } | ||
|
||
public ResponseStatus ResponseStatus { get; set; } | ||
} | ||
|
||
public class MyListRequestValidator : AbstractValidator<MyListRequest> | ||
{ | ||
public MyListRequestValidator() | ||
{ | ||
RuleFor(mlr => mlr).NotNull().WithMessage("Empty request"); | ||
RuleFor(mlr => mlr.Entries).NotNull().WithMessage("Expected property 'Entries' not found"); | ||
|
||
When(mlr => mlr.Entries != null, () => | ||
{ | ||
RuleFor(mlr => mlr.Entries.Count).Must(c => c >= 1).WithMessage("MyListRequest must contain at least 1 entry"); | ||
}); | ||
|
||
RuleForEach(mlr => mlr.Entries).SetValidator(new ListEntryValidator()); | ||
} | ||
} |