Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.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.