Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Quickly Configure SwaggerUI with Magicodes.SwaggerUI and Set Up API Grouping

Tech Nov 14 13

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);
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.