S2360 - Optional parameters should not be used: Add exception for API controller methods

Hi,

I would like to add an exception to the rule S2360 - Optional parameters should not be used for API Controller. In this case, it is allowed to use optional parameters to define default value for query parameter. So, API controller should be excluded from this rules.

  • What language is this for? c#, dotnet
  • Which rule? S2360
  • Why do you believe it’s a false-positive/false-negative?
  • Are you using
    • SonarQube Server : v10.6
  • How can we reproduce the problem? Use optional parameter in an API controller and the rule detects the issue.

Regards

2 Likes

Something like this would reproduce the issue:

[HttpGet]
public ActionResult<List<int>> Get([FromQuery] bool discontinuedOnly = false) // FP
{
    return [42];
}

I agree this should be excluded

1 Like

Hello @Furiphan,

Welcome to the community and thank you for reporting this issue!

I confirm this is a false positive.
I have created a ticket to fix in a future hardening sprint.

I would like to thanks @Corniel, your snippet helped me a lot in my investigation!

Have a nice day!

1 Like

Hello, can you give us the ticket number and a link to it please ? (to be able to follow it)

1 Like

Hello @rrousset,

The ticket has been created in our internal backlog which is private at the moment.

1 Like