Swashbuckle.SwaggerConfigurationExtension
2.2.0
dotnet add package Swashbuckle.SwaggerConfigurationExtension --version 2.2.0
NuGet\Install-Package Swashbuckle.SwaggerConfigurationExtension -Version 2.2.0
<PackageReference Include="Swashbuckle.SwaggerConfigurationExtension" Version="2.2.0" />
paket add Swashbuckle.SwaggerConfigurationExtension --version 2.2.0
#r "nuget: Swashbuckle.SwaggerConfigurationExtension, 2.2.0"
// 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
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 IT Solutions
Product | Versions 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. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Mvc.Versioning (>= 4.1.1)
- Microsoft.Extensions.DependencyInjection (>= 3.1.1)
- Swashbuckle.AspNetCore.SwaggerGen (>= 5.0.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
implements the swagger framework update for dotnet core 3.1.