Duplication in versionned Api

  • What language is this for? C#
  • Which rule? Duplication
  • Are you using
    • SonarQube : 10.2.1
  • How can we reproduce the problem?

In the pseudo-code below, the constructor and function declaration are the same. Same summary, same params.

SonarQube gives a duplication on the constructor and the summary and the descriptions of the parameters.

It shouldn’t.
In the case of versioning in a controller, duplication should be computed in another way.

namespace Api.Controllers.v1;

[ApiController]
[ApiVersion("1")]
[Route("api/v{version:apiVersion}/mail")]
public sealed class MailController : ControllerBase {
    public MailController (...) {
     ...
    }

    /// <summary>
    /// ...
    /// </summary>
    /// <param name=">...</param>
    /// <returns></returns>
    [Authorize]
    [HttpPost]
    [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
    [ProducesResponseType((int)HttpStatusCode.BadRequest)]
    [ProducesResponseType((int)HttpStatusCode.InternalServerError)]
    public async Task<ActionResult> Send(...)
    {
      ...
    }

}
namespace Api.Controllers.v2;

[ApiController]
[ApiVersion("2")]
[Route("api/v{version:apiVersion}/mail")]
public sealed class MailController : ControllerBase {
    public MailController (...) {
     ...
    }

    /// <summary>
    /// ...
    /// </summary>
    /// <param name=">...</param>
    /// <returns></returns>
    [Authorize]
    [HttpPost]
    [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
    [ProducesResponseType((int)HttpStatusCode.BadRequest)]
    [ProducesResponseType((int)HttpStatusCode.InternalServerError)]
    public async Task<ActionResult> Send(...)
    {
      ...
    }
}

Hi,

Unfortunately, duplication detection doesn’t take semantic meaning into account, just raw token duplication counts.

 
Ann

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.