feat: implementar versionado de API por URL v1. Closes #3
This commit is contained in:
@@ -1,7 +1,28 @@
|
||||
// ApiVersioningDemo.api/Program.cs
|
||||
using Asp.Versioning;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// 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;
|
||||
});
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
Reference in New Issue
Block a user