Swashbuckle.SwaggerConfigurationExtension 2.2.0

dotnet add package Swashbuckle.SwaggerConfigurationExtension --version 2.2.0                
NuGet\Install-Package Swashbuckle.SwaggerConfigurationExtension -Version 2.2.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="Swashbuckle.SwaggerConfigurationExtension" Version="2.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Swashbuckle.SwaggerConfigurationExtension --version 2.2.0                
#r "nuget: Swashbuckle.SwaggerConfigurationExtension, 2.2.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 Swashbuckle.SwaggerConfigurationExtension as a Cake Addin
#addin nuget:?package=Swashbuckle.SwaggerConfigurationExtension&version=2.2.0

// Install Swashbuckle.SwaggerConfigurationExtension as a Cake Tool
#tool nuget:?package=Swashbuckle.SwaggerConfigurationExtension&version=2.2.0                

Swashbuckle.SwaggerConfigurationExtension

Description: This project was created with the intention of versioning and configure a WebAPI in ASP.NET Core v3.1 using the Swagger (Swashbuckle.AspNetCore)

License: MIT License

Documented WebAPI example: https://swaggerconfig.azurewebsites.net
NOTES:
  • Do not install nuget Swashbuckle.AspNetCore if you are installing SwaggerConfigurationExtension to avoid conflicts.

  • Set XML Documentation File within csproject (path: select csproject and click properties/build/XML documentation file).

Use in Controllers you do want to version.

[ApiVersion("1.0")]
[Route("v{version:apiVersion}/[controller]")]

Use in Controllers you do not want to version. Note: You can use this tag for the Token Generation Controller.

[ApiVersionNeutral]
[Route("[controller]")]

Use in EndPoint [Controllers Methods] the verbs HTTP.

[HttpGet]
[HttpPost]
[HttpPut]
[HttpDelete]

Startup Example

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using Swashbuckle.SwaggerConfigurationExtension;
using System.Text;

namespace SwaggerConfigurationExtension.WebAPI.Test
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddControllers();

            services.AddApiVersioning(options =>
            {
                options.ApiVersionReader = new QueryStringApiVersionReader();
                options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
                options.ReportApiVersions = true;
            });

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    RequireExpirationTime = false,
                    ValidateIssuer = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer = Configuration.IssuerToken,
                    ValidAudience = Configuration.AudienceToken,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.SymmetricSecurityKey))
                };
            });

            /// Note: If you enable [hasAuthentication = true] the bearer token will be automatically configured within your swagger, without having to pass the optional variables.
            var swaggerConfigurationExtension = new SwaggerStartupConfigureServices(services, true)
                .SetProjectNameAndDescriptionn(Configuration.ProjectName, Configuration.ProjectDescription);

            services.Configure<MvcOptions>(options =>
            {
                //options.Filters.Add(new RequireHttpsAttribute()); //Need an SSL certificate to be uncommented
            });
        }
        
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();

            app.UseHttpsRedirection();
            app.UseRouting();

            app.UseCors(x => x
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //If you set "withInjectStyleSheet" to true, in "wwwroot" create a folder named "Stateless" and put a custom css file "swaggercustom.css"
            bool withInjectStyleSheet = true;
            string relativePathInjectStyleSheet = "../Stateless/swaggercustom.css";
            string swaggerDocumentationRoute = "Swagger";

            var swaggerStartupConfigure =  
            new SwaggerStartupConfigure(app, withInjectStyleSheet, swaggerDocumentationRoute,relativePathInjectStyleSheet)
            .RedirectToSwagger();
        }
    }
}

Vasconcellos Solutions

Vasconcellos IT Solutions

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 netcoreapp3.1 is compatible. 
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
2.2.0 5,357 2/14/2020
1.0.6 7,524 11/13/2018

implements the swagger framework update for dotnet core 3.1.