question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Check Web APIs returning ActionResult with status code 2xx

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Evangelinkcommented, Dec 2, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently Used Status Code And How To Return Them ...
In this article, you will learn frequently used status code and how to return them from ASP.NET Core Web API.
Read more >
HTTP Status Codes in ASP.NET Core
We discuss HTTP status codes and what they mean in this ASP.NET programming tutorial. Learn more about RESTful API.
Read more >
Controller action return types in ASP.NET Core web API
A 200 status code is returned with the corresponding Product object when the product does exist. Asynchronous action. Consider an asynchronous ...
Read more >
Return JSON with error status code MVC
Set a json object to return. The status code defaults to 500 return new JsonErrorResult(new { message = "Sorry, an internal error occurred....
Read more >
Unit Testing Controllers in ASP.NET Web API 2
The Get method calls Ok(product) if the product is found. In the unit test, make sure the return type is OkNegotiatedContentResult and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found