Hello.
I want to suggest a new rule - it’s specifically for c# but it might be useful for other languages as well. It is similar to rule: csharpsquid:S6965 and could also be an extension of that rule. The idea is to check for Http verb on all Controllers, not just limit it to REST API.
-
Basically all the Rule description and snippets should be the same as in that rule. Just extended to all Controller classes, not just classes with [ApiController] attribute (or whatever other way is done to recognize REST API Controllers.)
-
Noncompliant Code
*[Route("Customer")] // This route conflicts with GetCustomers action route
public async Task<IResult> ChangeCustomer([FromBody] CustomerData data) // Noncompliant
{
// ...
return Results.Ok();
}
[Route("Customer")] // This route conflicts with ChangeCustomer action route
public async Task<string> GetCustomers() // Noncompliant
{
return _customerRepository.GetAll();
}
- Compliant Code
[Route("Customer")]
[HttpPost]
public async Task<IResult> ChangeCustomer([FromBody] CustomerData data) // Compliant
{
// ...
return Results.Ok();
}
[HttpGet("Customer")]
public async Task<string> GetCustomers() // Compliant
{
return _customerRepository.GetAll();
}
- type : Code Smell?