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

Startup.cs下ConfigureServices代碼

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

Startup.cs下Configure代碼

 

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

ApiGroupAttribute

 若不想使用Microsoft.AspNetCore.Mvc下的ApiExplorerSettingsAttribute,能夠本身建一個ApiGroupAttribute。api

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

ApiGroupAttribute代碼以下文檔

效果

 

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

其餘

swagger經過輸出json如:「swagger/{documentName}/swagger.json「 顯示Api文檔,咱們能夠本身編寫解析json以實現本身的api文檔UI。swagger

相關文章
相關標籤/搜索