Skip to content

Check Web APIs returning ActionResult with status code 2xx #28600

Open
@sshanzel

Description

@sshanzel

Describe 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-mvc-execution-pipelineFeatures related to how MVC executes a controller or razor pagegood first issueGood for newcomers.help candidateIndicates that the issues may be a good fit for community to help with. Requires work from eng. teamseverity-minorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions