Reputation: 2220
I have 2 Get methods on my Web Api 2 controller:
// GET: api/ClientApi
public HttpResponseMessage GetAll()
{
IEnumerable<Client> clients = _clientRepository.GetAll();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, clients);
return response;
}
// GET: api/ClientApi/userId
public HttpResponseMessage GetAllClientsForUser(string userId)
{
IEnumerable<Client> clients = _clientRepository.GetAll();
var clientUsers = _clientUserRepository.FindAll(cu => cu.UserId == userId).ToList();
var clientsForUser = clients.Where(i => clientUsers.Select(cu => cu.ClientId).ToList().Contains(i.Id)).ToList();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, clientsForUser);
return response;
}
// GET: api/ClientApi/clientId
public HttpResponseMessage GetClientById(int id)
{
var client = _clientRepository.GetById<Client>(id);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, client);
return response;
}
Althought the names are different, I get the error:
Not supported by Swagger 2.0: Multiple operations with path 'api/Client' and method 'GET'.
Is there a way to go around this? I tried using an OperationFilter, found this on StackOverflow somewhere but that doesn't work...
Route.config:
routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Upvotes: 3
Views: 3138
Reputation: 125
I hope this is gonna help you, I fixed my issue this way, go to your swagger config file, add the following at the top:
using System.Linq;
and then around line 175, or use search and find ResolveConflictingActions you should find this line of code:
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
but it is commented out, comment that line of code in, and hopefully that will solve your issue, play around with it, since you might not just want the first one.
above the line of code you will see a short description for it. Hope this was helpful.
Upvotes: 7