Quickly Configure SwaggerUI with Magicodes.SwaggerUI and Set Up API Grouping
Magicodes.SwaggerUI
Quick configuration and integration of SwaggerUI for ASP.NET Core applications.
Features
- Simple configuration through JSON files to generate Swagger UI API format JSON and inttegration
- Supports API grouping and hiding
- Supports custom pages and authentication
NuGet Package
Install the package via NuGet:
Install-Package Magicodes.SwaggerUI
Update Log
2019.10.21
- 【NuGet】Magicodes.SwaggerUI 2.0.1
- 【Upgrade】Single document without grouping displays all APIs
- 【Refactor】Restructured directory organization
- 【Fix】Fixed issue where document comments were not loaded when running in local developmant environment
- 【Change】Auto-removes leading/trailing spaces and "/" prefix from GroupUrlPrefix
- 【Upgrade】Added support for grouped API hiding in addition to global API hiding
- 【Upgrade】API hiding now supports HTTP method configuration, default "*"
2019.10.19
- 【Upgrade】Added support for API grouping with non-invasive configuration, requiring no code changes - grouping achieved through configuraton alone (see examples below)
- 【Refactor】Refactored overall logic
Configuration Example
{
"SwaggerDoc": {
"IsEnabled": "true",
"DescribeAllEnumsAsStrings": false,
"SwaggerDocInfos": [
{
"IsEnabled": "true",
"Title": "Mobile App API Documentation",
"Version": "v1",
"GroupName": "MobileApp",
"Description": "",
"Contact": {
"Name": "Development Team A",
"Email": "dev@company.com"
},
"GroupUrlPrefix": "api/mobile/"
},
{
"IsEnabled": "true",
"Title": "Web Portal API Documentation",
"Version": "v2",
"GroupName": "WebPortal",
"Description": "",
"Contact": {
"Name": "Development Team B",
"Email": "dev@company.com"
},
"GroupUrlPrefix": "api/web/"
}
],
"HiddenApi": {
"IsEnabled": "true",
"HiddenUrls": "mobile/Users/{id}"
},
"UseFullNameForSchemaId": "false"
}
}
Service Registration
// Add custom API document generation with configuration support
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddCustomSwaggerGen(_configuration);
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
// Enable custom API document UI with configuration support
app.UseCustomSwaggerUI(_configuration);
}