Not supported by Swagger 2.0: Multiple operations with path
Solution 1
In the file AppStart/SwaggerConfig.cs
First one, you must import Linq
using System.Linq;
And add in the same file, this line
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
just inside of:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{ ...
One consideration:
In your controllers, you must use the Http methods
:
[HttpGet]
[Route("something")]
public List<model> something(){....}
[HttpGet]
[Route("something2")]
public List<model2> something2(){....}
[HttpPost]
[Route("mypost1")]
public List<model> mypost1(){....}
[HttpPost]
[Route("mypost2")]
public List<model2> mypost2(){....}
Solution 2
You have two options for the above two methods:
Combine two methods into single one with three parameters - each one will be in the query string
Have separate route urls like -
api/controller/byusername
andapi/controller/bycredentials
Solution 3
I understand this is an old thread. And im straying away from the OP Issue slightly. However i recently had this issue and spent a long time trying to figure out what was happening (this page is top of google for the issue). and it may help other from going through hours of pain.
my controllers all extended a base controller and i stupidly had a public function instead of a protected function. So swagger was picking up the public function as a duplicate.
Hope this helps others from spending unnecessary time.
Solution 4
You can change the route on your controller.
The default value is [Route("api/[controller]")]
You can change to [Route("api/[controller]/[action]")]
Solution 5
An answer I haven't seen: I bungled up usings.
My controller has some MVC items (List items) and thus has a link:
using System.Web.Http;
using System.Web.Mvc;
Because of this, somehow, it got registered twice (I assume). Problem was fixed by using the full qualification for RoutePrefix/Route/HttpGet and others.
namespace MyNameSpace
{
[System.Web.Http.RoutePrefix("api/Reports")]
public class ReportsController
{
{...constructor...}
[System.Web.Http.Route("Scans")]
[System.Web.Http.HttpGet,ResponseType(typeof(List<ReportClass>))]
public ascyn Task<HttpResponseMessage> GetScans() {...}
user2266837
Updated on November 24, 2020Comments
-
user2266837 over 3 years
I have integrated swagger in WebApi 2 application. It works fine when application has single controller. When I added second controller in the application. I got following error :
An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Credential' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for a potential workaround","ExceptionType":"System.NotSupportedException","StackTrace":" at Swashbuckle.Swagger.SwaggerGeneratorOptions.DefaultConflictingActionsResolver(IEnumerable
1 apiDescriptions)\r\n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable
1 apiDescriptions, SchemaRegistry schemaRegistry)\r\n at Swashbuckle.Swagger.SwaggerGenerator.<>c__DisplayClass7.b__4(IGrouping2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector, IEqualityComparer1 comparer)\r\n at Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion)\r\n at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Cors.CorsMessageHandler.<SendAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.HttpServer.
d__0.MoveNext()"} http://localhost:50950/swagger/docs/v1In the second controller I have added following two methods.
string Get(string username, string password); string Get(string credential);
If I comment one of the method. Then it works fine.
Any Idea how to fix it?
-
RandomUs1r about 6 yearsThis works, but it's important to understand why: if there's two matching routes, it'll only document the 1st one. Changing the method route names might be preferred by some.
-
Kishan Vaishnav almost 5 yearsThere should be a caveat in the answer. I would discourage people from using this method to solve this error. I'd rather prefer changing the route names.
-
Benjamin RD almost 5 years@KishanVaishnav that comment doen't apport anything good to the question. The question is clear, also the answer is right related with the question. The question doesn't is "is a good way". Please read again the question and try to apport something constructive
-
Kishan Vaishnav almost 5 years@MrMins My apologies. I don't understand why you have written about changing the SwaggerConfig. Wouldn't changing the route be sufficient?
-
Dan Cook about 3 yearsThis was it for me. Swagger was throwing
InvalidOperationException: The method 'get' on path '/Blog' is registered multiple times.
I had a base entity with a singlepublic
method.GetUserId()
. Changing this method toprotected
solved the issue for me. Due to the error message I was sure it was something to do with my multipleGET
methods, one of which took in a stringid
parameter, but no - the public method in base class was it.