-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Hi.
Thank you for SharpGrip.FluentValidation.AutoValidation.
Given an ASP.NET MVC endpoint like:
// POST api/Animals
public IActionResult Post([FromBody] CreateAnimalRequest request)
{
if (!this.ModelState.IsValid)
{
return this.ValidationProblem(this.ModelState);
}
}
With types defined:
public class CreateAnimalRequest
{
}
public class CreatePersonRequest : CreateAnimalRequest
{
public string Name { get; set; }
}
public class CreateAnimalRequestValidator : AbstractValidator<CreateAnimalRequest>
{
}
public class CreatePersonRequestValidator : AbstractValidator<CreatePersonRequest>
{
}
When an HTTP POST request is sent to api/Animals with the body:
{
"@odata.type": "#Animals.CreatePersonRequest",
"Name": "John Doe"
}
Then the CreateAnimalRequestValidator is unexpectedly being used for validation.
I expected CreatePersonRequestValidator to be used instead.
During runtime, request has the correct type CreatePersonRequest.
The problem seems to be that FluentValidationAutoValidationActionFilter.cs uses the method parameter's declared type to find the validator, but it should be using the method parameter's runtime (instance) type instead.
Thank you.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working