-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix S6934 FP: Attributes implementing IRouteTemplateProvider
or inheriting from RouteAttribute
#8985
Comments
RouteAttribute
RouteAttribute
Hello @CaringDev, Thank you for reporting this. I confirm it's a false positive. |
RouteAttribute
RouteAttribute
@CaringDev Seeing this example, I'd like to ask what's the use case here so that we can understand better and improve our analyzer. |
We use two attributes for easy, consistent setup of controllers: public sealed class ControllerRouteAttribute() : RouteAttribute("api/v{version:apiVersion}/[controller]");
public sealed class ActionRouteAttribute() : RouteAttribute("api/v{version:apiVersion}/[controller]/[action]"); Then, with "find usages", we can immediately see which controllers use "standard" behavior and which ones action method named routing. It also helps to devs (first two are not convention aware): [HttpGet("ActionMethod")]
[HttpGet(nameof(ActionMethod))]
[HttpGet("[action]")]
public void ActionMethod() { /* ... */ } We could also use e.g. public static class Routes {
public const string Controller = "api/v{version:apiVersion}/[controller]";
public const string Action = "api/v{version:apiVersion}/[controller]/[action]";
}
[Route(Routes.Controller)]
public class FooController : ControllerBase { /* ... */ } The FP should be fixed in any case though... I think there are as many legit use-cases as there are users out there :-) |
If I understand correctly, we should actually look for all the attributes that implement |
@CaringDev thanks a lot for the detailed explanation. |
RouteAttribute
IRouteTemplateProvider
IRouteTemplateProvider
IRouteTemplateProvider
No, we have several ASP.Net Core WebAPI (non-MVC) projects... would you think namespace Container;
[ControllerRoute]
public class FooController : ControllerBase
{
[HttpGet]
public string GetIndex() => "hi";
}
[ActionRoute]
public class BarController : ControllerBase
{
[HttpPost]
public void ServeDrinks() { }
} this would involve changing |
Thanks a lot again for the detailed reply, @CaringDev! I guess for this:
Areas might not work (but not sure). |
IRouteTemplateProvider
IRouteTemplateProvider
or inheriting from RouteAttribute
Description
Using attributes inheriting from
RouteAttribute
/ implementingIRouteTemplateProvider
are not considered for S6934Repro steps
Expected behavior
No S6934
Actual behavior
False positive S6934 for controllers decorated with an attribute inheriting from
RouteAttribute
/ implementingIRouteTemplateProvider
Known workarounds
None
Related information
The text was updated successfully, but these errors were encountered: