2026-03-07 19:05:10 -03:00
|
|
|
// ApiVersioningDemo.api/Program.cs
|
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
|
2026-03-06 12:04:37 -03:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
2026-03-07 19:05:10 -03:00
|
|
|
// CONFIGURACIÓN DE VERSIONADO
|
|
|
|
|
builder.Services.AddApiVersioning(options =>
|
|
|
|
|
{
|
|
|
|
|
// Si el cliente no especifica versión, usaremos la 1.0 por defecto
|
|
|
|
|
options.DefaultApiVersion = new ApiVersion(1, 0);
|
|
|
|
|
options.AssumeDefaultVersionWhenUnspecified = true;
|
|
|
|
|
|
|
|
|
|
// Esto añade una cabecera HTTP en las respuestas diciendo qué versiones existen (ej: api-supported-versions: 1.0, 2.0)
|
|
|
|
|
options.ReportApiVersions = true;
|
|
|
|
|
})
|
|
|
|
|
.AddMvc() // Integra el versionado con los Controladores
|
|
|
|
|
.AddApiExplorer(options =>
|
|
|
|
|
{
|
|
|
|
|
// Configura el formato para Swagger (ej: "v1", "v2")
|
|
|
|
|
options.GroupNameFormat = "'v'VVV";
|
|
|
|
|
options.SubstituteApiVersionInUrl = true;
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-06 12:04:37 -03:00
|
|
|
|
2026-03-07 19:05:10 -03:00
|
|
|
// Add services to the container.
|
2026-03-06 12:04:37 -03:00
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
|
|
|
builder.Services.AddOpenApi();
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.MapOpenApi();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
|
|
app.Run();
|