-
Notifications
You must be signed in to change notification settings - Fork 10.3k
API Analyzer doesn't recognize ControllerBase.ValidationProblem. #6061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for contacting us, @webwizgordon. |
|
Sorry, that was a typo. It should be |
Ah, I see. That's probably because it returns |
Is it intentional that |
I'm not sure. I tried to find the PR adding the method to see whether it had been discussed. @pranavkm probably knows. I'm guessing it might be because some people like to use 422 instead of 400, so you could override the method and return a different result. |
Yes, that was the intent. There are other issues, such as #4950, where the analyzer could infer the status code of an |
Describe the bug
The Web API Analyzer doesn't recognize
ControllerBase.ValidationProblem()
and does not prompt a codefix to add a[ProducesResponseType]
attribute like it does forControllerBase.BadRequest()
.To Reproduce
Steps to reproduce the behavior:
return ValidationProblem();
to a controller marked with[ApiController]
.Expected behavior
Analyzer catches the issue and underlines
return ValidationProblem();
Codefix prompt to add appropriate attributes to action.
Additional context
Using ASP.NET Core 2.2 and Microsoft.AspNetCore.Mvc.Api.Analyzers 2.2.0. Since the default
ModelStateInvalidFilter
usesValidationProblemDetails
to build a 400 response object, it makes sense that people may want to do the same for validation problems within actions so that the response format is consistent in both cases. Alternatively or additionally, there should be a way to opt intoControllerBase.BadRequest(ModelState)
usingValidationProblemDetails
to build its response object for consistency withModelStateInvalidFilter
.The text was updated successfully, but these errors were encountered: