Swashbuckle.SwaggerConfigurationExtension 2.2.0

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

Install-Package Swashbuckle.SwaggerConfigurationExtension -Version 2.2.0
dotnet add package Swashbuckle.SwaggerConfigurationExtension --version 2.2.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Swashbuckle.SwaggerConfigurationExtension, 2.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

Copyright (c) 2020 Pedro Vasconcellos

Sponsor: https://vasconcellos.solutions/

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

Sponsor

Vasconcellos Solutions

Vasconcellos IT Solutions

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

Copyright (c) 2020 Pedro Vasconcellos

Sponsor: https://vasconcellos.solutions/

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

Sponsor

Vasconcellos Solutions

Vasconcellos IT Solutions

Release Notes

implements the swagger framework update for dotnet core 3.1.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.0 448 2/14/2020
1.0.6 4,713 11/13/2018