2016-09-26 7 views
2

を持つ複数の操作は、私は私のWeb APIを2コントローラ上の2つのGetメソッドを持っている:闊歩:パス

// 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が異なっている、私はエラーを取得する:

Not supported by Swagger 2.0: Multiple operations with path 'api/Client' and method 'GET'.

これを回避する方法はありますか? 、私は、これはあなたが、私は私の問題をこのように固定つもり助けであると思います

routes.MapHttpRoute(
     name: "API Default", 
     routeTemplate: "api/{controller}/{id}", 
     defaults: new { id = RouteParameter.Optional } 
    ); 

答えて

0

:私は...どこかStackOverflowの上でこれを見つけたが、それが動作しない、OperationFilterを使用して

Route.configを試してみました

:あなたはこのコード行を見つける必要があり

using System.Linq; 

して、行175の周りに、または検索を使用してResolveConflictingActionsを見つける:先頭に以下を追加し、あなたの闊歩設定ファイルにアクセスしてください

しかし、あなたが最初のものだけを望んでいない可能性があるので、あなたの問題を解決することができればそれはコメント行にコメントされています。

コード行の上に簡単な説明があります。これが参考になることを願っています。