DarkruneDK.Swagger 1.0.1

dotnet add package DarkruneDK.Swagger --version 1.0.1
                    
NuGet\Install-Package DarkruneDK.Swagger -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DarkruneDK.Swagger" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DarkruneDK.Swagger" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="DarkruneDK.Swagger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DarkruneDK.Swagger --version 1.0.1
                    
#r "nuget: DarkruneDK.Swagger, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DarkruneDK.Swagger@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DarkruneDK.Swagger&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=DarkruneDK.Swagger&version=1.0.1
                    
Install as a Cake Tool

DarkruneDK's Swagger Extensions

This is a small library that provides some extensions for Swagger in .NET 10.0 projects. It includes a way to mark certain enums so they are displayed by Swagger as their string values instead of their integer values.

Both the integer and string values of the enum will still work, but Swagger will display the string value in the dropdowns.

How do I use it?

In order to enable this functionality, you need to add this package to your project.

After that you need to add the following line to your Program.cs file after your services.AddControllers() like this:

services.AddControllers().AddJsonOptions(options =>
{
    options.JsonSerializerOptions.Converters.Add(new EnumToStringConverter());
});

Now you can mark your enums with the [EnumToString] attribute like this:

[EnumToString]
public enum CustomerType
{
    Unknown = 0,
    Individual = 1,
}

This is all it takes to make the change to Swagger. Now when you look at the Swagger UI, you will see the string values of the enum instead of the integer values.

Filters

The package also includes two filters which can help with documentation, as it will be created at runtime and is in-code. This also means you don't need to generate large xml files for the documenation, which can save some space.

These two filters are in the package to help with that:

  • SwaggerDescriptionOperationFilter - This filter enables the use of SwaggerDescriptionAttribute on the method level, which allows you to add a description to the method in the Swagger UI.
  • SwaggerDescriptionDocumentFilter - This filter enables the use of SwaggerDescriptionAttribute on the controller level, which allows you to add a description to the controller in the Swagger UI.

The way to enable the filters is to extend the AddSwaggerGen method in your Program.cs file like this:

services.AddSwaggerGen(options =>
{
    options.OperationFilter<SwaggerDescriptionOperationFilter>();
    options.DocumentFilter<SwaggerDescriptionDocumentFilter>();
});

This will enable the filters and allow you to use the SwaggerDescriptionAttribute on your methods and controllers.

The attribute can be used like this:

[SwaggerDescription("Test controller.")]
[Route("[controller]")]
[ApiController]
public class TestController : ControllerBase
{
    [SwaggerDescription("Gets the chosen customer.", "Gets customer.")]
    [Route("GetCustomer/{customer}")]
    [HttpGet]
    public IActionResult GetCustomer(CustomerType customer)
    {
        return Ok();
    }
}

This will display the description in the Swagger UI for both the controller and the method.

NOTE: The summary is ignored at controller level documentation, as there exist no summary field for controllers in the Swagger UI. The summary is only used for methods.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 123 7/16/2026
1.0.0 123 7/14/2026

Added a couple of filters to help with documentation. This means I needed to add a dependency to SwaggerGen.