Check Web APIs returning ActionResult with status code 2xx
See original GitHub issueDescribe the problem you are trying to solve
ActionResult
accepts a generic parameter but doesn’t enforce strict-typing (related issue).
But as what we have discussed here, it is ideal to improve the Analyzers instead of making the changes with the ControllerBase
.
Describe suggestions on how to achieve the rule
I am literally new with Analyzers (like a few hours ago) but it would be awesome if we will be able to check the MethodDeclarationSyntax
of a ReturnStatementSyntax
to see if the content type of the returned OkObjectResult
matches the identified generic parameter from the method itself (please do correct me if I’m wrong on what I have initially thought for the solution).
I suggest displaying red curly underlines to notify the developer of the mismatch.
Additional context
Even though I literally haven’t tried making a single rule, I did a few moments ago but failed miserably (link to the repo - actual rule). Hence, went here to seek help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Does it mean this ticket should be moved across to aspnetcore repo? If not I can have a look at the implementation but with my poor web experience I’d be happy to have someone providing “test” cases of when to report and when not to.
It would go here btw https://github.com/dotnet/aspnetcore/tree/master/src/Analyzers/Analyzers/src