Unchase.Swashbuckle.AspNetCore.Extensions 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Unchase.Swashbuckle.AspNetCore.Extensions --version 1.1.0                
NuGet\Install-Package Unchase.Swashbuckle.AspNetCore.Extensions -Version 1.1.0                
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="Unchase.Swashbuckle.AspNetCore.Extensions" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Unchase.Swashbuckle.AspNetCore.Extensions --version 1.1.0                
#r "nuget: Unchase.Swashbuckle.AspNetCore.Extensions, 1.1.0"                
#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.
// Install Unchase.Swashbuckle.AspNetCore.Extensions as a Cake Addin
#addin nuget:?package=Unchase.Swashbuckle.AspNetCore.Extensions&version=1.1.0

// Install Unchase.Swashbuckle.AspNetCore.Extensions as a Cake Tool
#tool nuget:?package=Unchase.Swashbuckle.AspNetCore.Extensions&version=1.1.0                

Unchase Swashbuckle Asp.Net Core Extensions Logo

Unchase Swashbuckle Asp.Net Core Extensions is a library contains a bunch of extensions (filters) for Swashbuckle.AspNetCore.

The project is developed and maintained by Nikolay Chebotov (Unchase).

Getting Started

To use the extensions:

  1. First install the NuGet package
  2. Then use whichever extensions (filters) you need

Extensions (Filters) use

  1. For fix enums:
  • In the ConfigureServices method of Startup.cs, inside your AddSwaggerGen call, enable whichever extensions (filters) you need:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();

    services.AddSwaggerGen(options =>
    {
        options.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
        
        options.SwaggerDoc("v1", new Info {Title = "My API", Version = "v2"});

        // Add filters to fix enums
        options.AddEnumsWithValuesFixFilters(true);
        // or custom use:
        //options.SchemaFilter<XEnumNamesSchemaFilter>(); // add schema filter to fix enums (add 'x-enumNames' for NSwag) in schema
        //options.ParameterFilter<XEnumNamesParameterFilter>(); // add parameter filter to fix enums (add 'x-enumNames' for NSwag) in schema parameters
        //options.DocumentFilter<DisplayEnumsWithValuesDocumentFilter>(true); // add document filter to fix enums displaying in swagger document

        // Include xml-comments from xml-file generated by project
        var filePath = Path.Combine(AppContext.BaseDirectory, "WebApi2.0-Swashbuckle.xml");
        options.IncludeXmlComments(filePath);
    });
}
  1. For hiding SwaggerDocumentation PathItems without accepted roles:
  • In the ConfigureServices method of Startup.cs, inside your AddSwaggerGen call, enable whichever extensions (filters) you need:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // add Security information to each operation for OAuth2
        options.OperationFilter<SecurityRequirementsOperationFilter>();

        // optional: if you're using the SecurityRequirementsOperationFilter, you also need to tell Swashbuckle you're using OAuth2
        options.AddSecurityDefinition("oauth2", new ApiKeyScheme
        {
            Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
            In = "header",
            Name = "Authorization",
            Type = "apiKey"
        });
    });
}
  • In the Configure method of Startup.cs, inside your UseSwagger call, enable whichever extensions (filters) you need:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...

    app.UseSwagger(c =>
    {
        c.PreSerializeFilters.Add((swaggerDoc, httpRequest) =>
        {
            // hide all SwaggerDocument PathItems with added Security information for OAuth2 without accepted roles (for example, "AcceptedRole")
            swaggerDoc.HidePathItemsWithoutAcceptedRoles(new List<string> {"AcceptedRole"});
        });
    });

    ...
}

Features

See in repository

Feedback

Please feel free to add your request a feature or report a bug. Thank you in advance!

Thank me!

If you like what I am doing and you would like to thank me, please consider:

Buy me a coffe!

Thank you for your support!


Copyright 2019 Nikolay Chebotov (Unchase) - Provided under the Apache License 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on Unchase.Swashbuckle.AspNetCore.Extensions:

Package Downloads
Tessa.Web

TESSA library for building ASP.NET Core applications.

Pipoburgos.SharedKernel.Api

C# DDD Distributed Services Layer

Tradeber.AbpCore.ServiceFabric

tradeber 基础设施库

Pipoburgos.SharedKernel.Api.Gateway

C# DDD Distributed Services Layer

Xinghe.Utility

XH基础库(内部使用)

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Unchase.Swashbuckle.AspNetCore.Extensions:

Repository Stars
exceptionless/Exceptionless
Exceptionless application
meysamhadeli/booking-microservices
Practical microservices, built with .Net 8, DDD, CQRS, Event Sourcing, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
mehdihadeli/food-delivery-microservices
🍔 A practical and imaginary food delivery microservices, built with .Net 8, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
Version Downloads Last updated
2.7.1 2,036,318 12/11/2022
2.7.0 1,623 12/10/2022
2.6.12 1,195,179 10/5/2021
2.6.11 9,434 9/29/2021
2.6.9 35,050 8/30/2021
2.6.8 3,658 8/26/2021
2.6.7 845 8/26/2021
2.6.6 10,055 8/26/2021
2.6.5 892 8/26/2021
2.6.4 916 8/26/2021
2.6.3 914 8/26/2021
2.6.2 1,539 8/26/2021
2.6.0 431,832 3/6/2021
2.5.2 107,592 2/9/2021
2.5.1 3,212 2/5/2021
2.5.0 220,136 10/15/2020
2.4.1 32,333 10/13/2020
2.4.0 1,926 10/11/2020
2.3.13 17,889 10/7/2020
2.3.12 5,012 9/21/2020
2.3.11 2,331 9/17/2020
2.3.10 68,724 7/29/2020
2.3.9 1,711 7/28/2020
2.3.8 30,346 7/6/2020
2.3.7 1,073 7/6/2020
2.3.6 1,078 7/6/2020
2.3.5 1,076 7/6/2020
2.3.4 124,176 6/11/2020
2.3.3 197,216 3/25/2020
2.3.2 1,160 3/25/2020
2.3.1 1,041 3/25/2020
2.3.0 2,585 3/22/2020
2.2.6 2,474 3/22/2020
2.2.5 29,391 3/2/2020
2.2.4 1,118 3/2/2020
2.2.3 1,097 3/2/2020
2.2.2 1,105 2/29/2020
2.2.1 1,120 2/29/2020
2.2.0 1,207 2/28/2020
2.1.7 11,134 2/21/2020
2.1.6 1,164 2/21/2020
2.1.5 1,124 2/21/2020
2.1.4 1,397 2/20/2020
2.1.3 1,119 2/20/2020
2.1.2 1,074 2/20/2020
2.1.1 1,109 2/19/2020
2.1.0 1,156 2/19/2020
2.0.1 1,173 2/18/2020
2.0.0 12,457 2/8/2020
1.1.4 5,225 12/26/2019
1.1.3 1,321 11/29/2019
1.1.2 1,261 11/22/2019
1.1.1 6,450 5/13/2019
1.1.0 1,198 5/7/2019
1.0.2 1,147 5/1/2019
1.0.0 3,301 5/1/2019