2015-10-06 118 views
9

當我訪問招搖網址:http://localhost:28483/swagger/ui/index,它生成此錯誤:的Web API - 揚鞭文檔錯誤500

500 : undefined http://localhost:28483/swagger/docs/v1 

任何想法?

更新時間: 看到這個細節錯誤在Firebug:

Not supported by Swagger 2.0: Multiple operations 
with path 'api/BimModel' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for 
a potential workaround 
+0

你有什麼錯誤? –

+0

@CongLe:這就是我在瀏覽器中獲得的一切。 –

回答

7

揚鞭可能會考慮兩個動作爲一個操作(就像這個常見的場景的情況下)...

GET api/Products 
GET api/Products/{id} 

看來你可以使用attribute routing修復它並使用上面這些屬性你的舉動如此激動人心,會分開承認他們。

[Route("api/Products")] 

[Route("api/Products/{id:guid}")] 
1

在控制器,它有兩個不同的GET操作,它是由揚鞭不允許的。 我建議要麼爲每個控制器只有單一的GET操作或modify the router in WebApiConfig

+1

不幸的是,在ApiConfig中修改路由器並沒有幫助。仍然有'不支持Swagger 2.0:多路徑操作...'。看起來我必須爲每個get方法創建新的控制器,或者有什麼其他方式來強制swagger進行合作(某些屬性,...)? – wolen

3

您是否嘗試過在您的swagger配置中啓用此功能?

c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); 
+1

儘管這可能會解決錯誤,但其他操作不會顯示出來然後在大搖大擺。 – Evan

0

我在將屬性路由與默認路由混合時遇到同樣的問題。 當我刪除默認路由時,問題就消失了。缺點是,沒有定義默認路由,我不得不將屬性路由添加到我的所有控制器。

所以從我的WebApiConfig我刪除:

config.Routes.MapHttpRoute(
    name: "DefaultApi", 
    routeTemplate: "{controller}/{id}", 
    defaults: new { id = RouteParameter.Optional } 
); 

而添加的屬性路由到我的控制器:

[Route("Session")] // Added this attribute 
public async Task<IHttpActionResult> Get() 
...  
[Route("Session/{id}")] // Added this attribute 
public async Task<IHttpActionResult> Get(int id) 

在現實中,我在我的控制器使用[RoutePrefix("Session")]和我的方法使用[Route("")],但結果應該是一樣的。

0

由於參數名稱在屬性路由語句和方法簽名之間不匹配,我得到此錯誤。

[HttpGet("{id}")] 
public IActionResult Get(string deviceNumber){ 
... 

將「{id}」更改爲「{deviceNumber}」後,它修復了錯誤。