Asp.net-Web-Api

Web Api - Swagger 文件錯誤 500

  • October 7, 2018

當我訪問 swagger url:http://localhost:28483/swagger/ui/index時,它會生成此錯誤:

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

有任何想法嗎?

更新:在螢火蟲中查看此詳細錯誤:

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

Swagger 可能會將兩個操作視為一個操作(例如在這種常見情況下)……

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

看來您可以使用屬性路由來解決此問題,並在您的操作上方使用這些屬性,因此 swagger 將分別辨識它們。

[Route("api/Products")]

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

您是否嘗試過在您的招搖配置中啟用此功能?

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

引用自:https://stackoverflow.com/questions/32973669