question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination

See original GitHub issue

Hi,

I have the following API controller with 2 GET actions

[Route("api/[controller]")]
[ApiController]
public class InvestorsController : ControllerBase
{
    [HttpGet("{id:guid}", Name = nameof(GetCrmInvestor))]
    public async Task<ActionResult<Dto.Crm.InvestorDto>> GetCrmInvestor(Guid id)
    {
    }

    [HttpGet("{id:int}", Name = nameof(GetCrowdInvestor))]
    public async Task<ActionResult<InvestorDto>> GetCrowdInvestor(int id)
    {
    }
}

I can successfully call both of these endpoints using Postman - 1 with an int, 1 with a guid - however, Swagger throws an exception:

Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination "GET api/Investors/{id}" for actions - {full path to method}.GetCrmInvestor, {full path to method}.GetCrowdInvestor. Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

This API is written in ASP.NET Core 5 (net5.0). Using Nuget package Swashbuckle.AspNetCore Version 6.0.7

This seems different to #1713 as I have provided a route name.

Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
abdollahkahnecommented, Sep 27, 2021

@domaindrivendev What if we have this conflict regarding different API versions? For example I have this two methods which respond to /weatherforecast path according to specified api version but now swagger UI thrown the above exception.

  // Get /weatherforecast
        [Authorize]
        [HttpGet]
        [ProducesResponseType(200)]
        [MapToApiVersion("2.0")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Get(3);
        }

         // Get /weatherforecast
        [Authorize]
        [HttpGet]
        [ProducesResponseType(200)]
        [MapToApiVersion("1.0")]
        public IEnumerable<WeatherForecast> GetV1()
        {
            return Get(5);
        }

       // Get /weatherforecast/7
        [Authorize]
        [HttpGet("{days:int}")]
        [ProducesResponseType(200)]
        public IEnumerable<WeatherForecast> Get(int days)
        {
            var rng = new Random();
            return Enumerable.Range(1, days).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
            })
            .ToArray();
        }
1reaction
domaindrivendevcommented, Feb 27, 2021

Swashbuckle is built on top of the OpenAPI Specification. That is, it generates an OpenAPI document that describes your API and then uses that document to power the swagger-ui.

In OpenAPI, each operation is uniquely identified by a combination a “path template” and a HTTP method. In this context, a “path template” is a relative path with curly braces (if applicable|) to mark a section of a URL path as replaceable using path parameter names. Similar to a “route template”, which is a concept internal to ASP.NET Core, but curly braces would only include parameter names, and not route constraint syntax.

With this in mind, your two operations would have the same “path template” (/investors/{id}) and the same HTTP method, and so the generated OpenAPI document would not be valid, hence the exception. To workaround this, you need to have something in the “path template” to distinguish them from eachother, and in this case it seems the parameter name is your best option because it wouldn’t change the API behavior in any way.

[Route("api/[controller]")]
[ApiController]
public class InvestorsController : ControllerBase
{
    [HttpGet("{guidId:guid}", Name = nameof(GetCrmInvestor))]
    public async Task<ActionResult<Dto.Crm.InvestorDto>> GetCrmInvestor(Guid guidId)
    {
    }

    [HttpGet("{intId:int}", Name = nameof(GetCrowdInvestor))]
    public async Task<ActionResult<InvestorDto>> GetCrowdInvestor(int intId)
    {
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Actions require unique method/path combination for Swagger
when you specify HttpGet by not providing template, Swashbuckle tries to use default map for both of them. hence conflict occurs.
Read more >
Conflicting method/path combination for actions in Swagger ...
Cause. There is a confliction method/path in ReportDesignerController. Swagger requires actions to have unique methods/paths. Solution. Swashbuckle.
Read more >
Actions require a unique method/path combination for ...
ERR] An unhandled exception has occurred while executing the request. Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting ...
Read more >
ASP.NET Core Swagger error - Conflicting method/path ...
After adding a new method to a controller, my OpenAPI(Swagger) ... Conflicting method/path combination "POST api/Orders" for actions ...
Read more >
How to Swagger API Versioning in ASP.NET Core
An unhandled exception has occurred while executing the request. Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found