Quick.SwaggerWidthApiVersion
1.1.0
dotnet add package Quick.SwaggerWidthApiVersion --version 1.1.0
NuGet\Install-Package Quick.SwaggerWidthApiVersion -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="Quick.SwaggerWidthApiVersion" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Quick.SwaggerWidthApiVersion --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Quick.SwaggerWidthApiVersion, 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 Quick.SwaggerWidthApiVersion as a Cake Addin
#addin nuget:?package=Quick.SwaggerWidthApiVersion&version=1.1.0
// Install Quick.SwaggerWidthApiVersion as a Cake Tool
#tool nuget:?package=Quick.SwaggerWidthApiVersion&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Quick.SwaggerWidthApiVersion
Quick start width Swagger and Api Version in a API Rest Core.
Package | Version | Description |
---|---|---|
Quick.Swagger |
Getting Started
// Program.cs
using Quick.SwaggerWidthApiVersion;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddQuickSwaggerWidthApiVersion("Demo", 2);
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.AddQuickUseSwagger();
app.Run();
Controller width attribute version
[ApiVersion("1.0", Deprecated = false)]
[ApiController]
[Route("/api/v{version:apiVersion}/[controller]")]
public class DemoController : ControllerBase
{
...
[MapToApiVersion("1.0")]
[HttpGet]
public IActionResult Get()
{
return Ok("Hello World");
}
...
}
Step 1 in the builder
Replace 'AddSwaggerGen' by 'AddQuickSwaggerWidthApiVersion'
Before
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc(
"v1",
new OpenApiInfo
{
Title = "Demo",
Version = "v1"
});
c.SwaggerDoc(
"v2",
new OpenApiInfo
{
Title = "Demo",
Version = "v2"
});
//c.DocumentFilter<VersionnDocsFilter>();
c.OperationFilter<RemoveVersionParameterFilter>();
c.DocumentFilter<ReplaceVersionWithExactValueInPathFilter>();
c.EnableAnnotations();
});
builder.Services.AddApiVersioning(o =>
{
o.AssumeDefaultVersionWhenUnspecified = true;
o.DefaultApiVersion = new ApiVersion(1,0);
o.ReportApiVersions = true;
o.ApiVersionReader = new HeaderApiVersionReader();
});
builder.Services.AddVersionedApiExplorer(o => {
o.GroupNameFormat = "'v'VVV";
o.SubstituteApiVersionInUrl = true;
});
Replace by
builder.Services.AddQuickSwaggerWidthApiVersion("Demo", 2); // 2 -> "v1","v2"
Or replace by
builder.Services.AddQuickSwaggerWidthApiVersion("Demo","v1", "v1.1", "v2");
Or replace by
builder.Services.AddQuickSwaggerWidthApiVersion("Demo", new List<OpenApiInfo>(){
new OpenApiInfo
{
Title = "Demo",
Version = "v1"
});
c.SwaggerDoc(
"v2",
new OpenApiInfo
{
Title = "Demo",
Version = "v2"
});
});
Step 2 final step in the app
Replace 'app.UseSwagger' and 'app.UseSwaggerUI' by 'AddQuickUseSwagger'
Before
if (app.Environment.IsDevelopment())
{
app.Logger.LogInformation($"Mode Developpement");
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Demo v1");
c.SwaggerEndpoint("/swagger/v2/swagger.json", "Demo v2");
});
app.UseDeveloperExceptionPage();
}
Replace
app.AddQuickUseSwagger();
Sample
See project ApiDemo
Build and Development
dotnet build --configuration release ./Quick.SwaggerWidthApiVersion.csproj
dotnet pack -o ./Artefacts ./Quick.SwaggerWidthApiVersion.csproj
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.10)
- Microsoft.AspNetCore.Mvc.Versioning (>= 5.1.0)
- Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer (>= 5.1.0)
- Swashbuckle.AspNetCore.Annotations (>= 6.5.0)
- Swashbuckle.AspNetCore.Swagger (>= 6.5.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.