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 (4)

Showing the top 4 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.
aehyok/.NET8.0
net8.0 efcore mysql redis rabbitmq 微服务
Version Downloads Last updated
2.7.1 2,074,283 12/11/2022
2.7.0 1,653 12/10/2022
2.6.12 1,199,097 10/5/2021
2.6.11 9,442 9/29/2021
2.6.9 35,083 8/30/2021
2.6.8 3,660 8/26/2021
2.6.7 847 8/26/2021
2.6.6 10,057 8/26/2021
2.6.5 894 8/26/2021
2.6.4 918 8/26/2021
2.6.3 916 8/26/2021
2.6.2 1,541 8/26/2021
2.6.0 432,993 3/6/2021
2.5.2 107,804 2/9/2021
2.5.1 3,214 2/5/2021
2.5.0 220,615 10/15/2020
2.4.1 32,335 10/13/2020
2.4.0 1,928 10/11/2020
2.3.13 17,970 10/7/2020
2.3.12 5,014 9/21/2020
2.3.11 2,333 9/17/2020
2.3.10 69,544 7/29/2020
2.3.9 1,713 7/28/2020
2.3.8 30,349 7/6/2020
2.3.7 1,075 7/6/2020
2.3.6 1,080 7/6/2020
2.3.5 1,078 7/6/2020
2.3.4 124,206 6/11/2020
2.3.3 197,285 3/25/2020
2.3.2 1,162 3/25/2020
2.3.1 1,043 3/25/2020
2.3.0 2,587 3/22/2020
2.2.6 2,476 3/22/2020
2.2.5 29,394 3/2/2020
2.2.4 1,120 3/2/2020
2.2.3 1,099 3/2/2020
2.2.2 1,107 2/29/2020
2.2.1 1,122 2/29/2020
2.2.0 1,210 2/28/2020
2.1.7 11,186 2/21/2020
2.1.6 1,166 2/21/2020
2.1.5 1,126 2/21/2020
2.1.4 1,399 2/20/2020
2.1.3 1,121 2/20/2020
2.1.2 1,076 2/20/2020
2.1.1 1,111 2/19/2020
2.1.0 1,158 2/19/2020
2.0.1 1,175 2/18/2020
2.0.0 12,461 2/8/2020
1.1.4 5,227 12/26/2019
1.1.3 1,323 11/29/2019
1.1.2 1,263 11/22/2019
1.1.1 6,452 5/13/2019
1.1.0 1,200 5/7/2019
1.0.2 1,151 5/1/2019
1.0.0 3,317 5/1/2019