【dotNet Core】Swagger下簡單的給WebApi分組


Startup.cs下ConfigureServices代碼

這里主要在DocInclusionPredicate控制輸出那些api。

Startup.cs下Configure代碼

 

給Controllers或Action添加[ApiExplorerSettings(GroupName= "ApiGroupName")]

ApiGroupAttribute

 若不想使用Microsoft.AspNetCore.Mvc下的ApiExplorerSettingsAttribute,可以自己建一個ApiGroupAttribute。

請將上面代碼中的ApiExplorerSettingsAttribute替換為ApiGroupAttribute,ApiExplorerSettings替換為ApiGroup。

ApiGroupAttribute代碼如下

效果

 

若不使用[ApiExplorerSettings(GroupName= "GroupName")] api將在V1顯示。

其他

swagger通過輸出json如:“swagger/{documentName}/swagger.json“ 顯示Api文檔,我們可以自己編寫解析json以實現自己的api文檔UI。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM