The 2nd fluent validator is not called when api method has 2 request models
See original GitHub issueWhich version of FluentValidation are you using?
<PackageReference Include="FluentValidation.AspNetCore" Version="8.6.2" />
Which version of ASP.NET are you using?
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.3" />
Describe the issue that you’re having Do you support fluent validation for this kind of controller method signature?
[HttpPut("api/content/{providerId}/{releaseAssetId}/movies")]
public async Task<ActionResult> PutMovieAsset([FromRoute] ReleaseRequestModel routeModel,
[FromBody] PutMovieAssetRequestModel model, CancellationToken cancellationToken)
The problem is that fluent validator of ReleaseRequestModel is called but the one for PutMovieAssetRequestModel is not.
Validators are all defined in the same project as Startup, but in their own subdirectories:
.AddFluentValidation(options =>
{
options.RunDefaultMvcValidationAfterFluentValidationExecutes = true;
options.ImplicitlyValidateChildProperties = true;
options.RegisterValidatorsFromAssemblyContaining<Startup>();
})
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Fluent Validation not validating on request
I've updated the object, so this should be getting hit. I added the CreditLimit as 101. Why isn't this working in the pipeline...
Read more >Built-In, Nested, Custom Validators with FluentValidation
In this article we are going to learn more about different Validators with FluentValidation, that we can use to protect our app from...
Read more >Built-in Validators — FluentValidation documentation
FluentValidation ships with several built-in validators. ... Ensures that the specified property is not null, an empty string or whitespace (or the default ......
Read more >Conditions — FluentValidation documentation
By default FluentValidation will apply the condition to all preceding validators in the same call to RuleFor . If you only want the...
Read more >Using Fluent Validation in ASP.NET Core
The GO-TO Approach for Model validation in any .NET Application is Data Annotations, where you have to declare attributes over the property of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
I just tried this and can’t reproduce the problem - it worked correctly for me. Both validators were instantiated and executed, and both sets of validation failures were added to ModelState.
Please put together a small sample application that reproduces the issue (ideally in a github repo that I can pull down) then I’ll be able to investigate further. Thanks.
That makes sense indeed, top level validators don’t have to use generic types. Leftover from some previous code changes. Thanks