dotnet / dotnet/aspnetcore

Check Web APIs returning ActionResult with status code 2xx

Open
#28,600 11 comments 1 reaction 0 assignees View on GitHub
affected-few area-mvc enhancement feature-mvc-execution-pipeline good first issue help wanted severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Describe the problem you are trying to solve
`ActionResult` accepts a generic parameter but doesn't enforce strict-typing (related [issue](https://github.com/dotnet/aspnetcore/issues/28198)).
But as what we have discussed [here](https://github.com/dotnet/aspnetcore/issues/28198#issuecomment-734861517), 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](https://github.com/sshanzel/RoslynAnalyzer-Proposal) - actual [rule](https://github.com/sshanzel/RoslynAnalyzer-Proposal/blob/main/ProducesResponseTypeAnalyzer/ProducesResponseTypeAnalyzer/ProducesResponseTypeAnalyzerAnalyzer.cs)). Hence, went here to seek help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.