0

The specific error is:

SwaggerGeneratorException: Conflicting method/path combination "GET Exercise" for actions - FitnessTracker.Controllers.ExerciseController.GetExerciseList (FitnessTracker),FitnessTracker.Controllers.ExerciseController.GetExerciseById (FitnessTracker). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

I thought web api inferred the verb from the function prefix, ie. Get or Post and then as long as the function name was unique or even the parameter list was unique that was sufficient.

Here's my controller:

[ApiController]
[Route("[controller]")]
public class ExerciseController : ControllerBase
{
    private readonly IDL DL;
    private readonly ILogger<ExerciseController> logger;

    public ExerciseController(IDL dL, ILogger<ExerciseController> logger)
    {
        DL = dL;
        this.logger = logger;
    }

    [HttpGet(Name = "GetExerciseList")]
    [Route("api/[controller]/[action]")]
    public List<Exercise> GetExerciseList()
    {
        return DL.GetExerciseList();
    }

    [HttpGet(Name = "GetExerciseById")]
    [Route("api/[controller]/[action]")]
    public Exercise GetExerciseById(string exerciseId)
    {
        return DL.GetExerciseById(exerciseId);
    }
}

I'm also not really clear on the purpose of Name = "GetExerciseList" in the attribute, seems redundant.

So how is it getting confused? The functions are distinct in both name and parameter list.

I've tried various Route attributes, none of which resolve the issue, including:

[Route("api/[controller]/[action]")]
[Route("api/[Controller]/ExerciseList")]
[Route("api/Exercise/ExerciseList")]
[Route("RoutingSucks")]
[Route("ICanPutAnythingHereAndItMakesNoDifference")]
Legion
  • 3,922
  • 8
  • 51
  • 95
  • Does this answer your question? [Actions require unique method/path combination for Swagger](https://stackoverflow.com/questions/54267137/actions-require-unique-method-path-combination-for-swagger) – ArunPratap Jan 14 '23 at 18:23
  • @ArunPratap No. I've tried adding the Route attribute but it doesn't fix anything. See my edit. – Legion Jan 14 '23 at 18:26
  • Try changing the route so it ends with `[action]/{exerciseId}` for the action method that has the `string exerciseId` parameter – Peter B Jan 14 '23 at 18:37
  • Try using routing like this. On your class set routing like this: `Route["api/[controller]"]` and on your action methods like this `[HttpGet]` and `[HttpGe"{excersizeId}"]` . – Menyus Jan 14 '23 at 18:43

1 Answers1

0

Turns out the Name parameter for the HttpGet attribute is useless (at least in this context). Likewise the Route attribute also serves no purpose. The solution that worked was to supply the relative route in the HttpGet attribute as follows:

    [HttpGet("ExerciseList")]
    public List<Exercise> GetExerciseList()
    {
        return DL.GetExerciseList();
    }

    [HttpGet("ExerciseById/{exerciseId}")]
    public Exercise GetExerciseById(string exerciseId)
    {
        return DL.GetExerciseById(exerciseId);
    }
Legion
  • 3,922
  • 8
  • 51
  • 95