diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index baa0f66..63bc857 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -220,6 +220,8 @@ jobs: uses: docker/build-push-action@v5 with: context: . + build-args: | + API_VERSION=${{ steps.sanitize-version.outputs.version }} file: ./src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile b/src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile index e839061..5bf68c5 100644 --- a/src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile +++ b/src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile @@ -15,7 +15,8 @@ RUN dotnet restore src/FIAP.TechChallenge.ByteMeBurger.Api FROM build AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +ARG API_VERSION +RUN dotnet publish "src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$API_VERSION FROM base AS final diff --git a/src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs b/src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs index 28f2604..cefdc7e 100644 --- a/src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs +++ b/src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs @@ -52,11 +52,12 @@ public static void Main(string[] args) // https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-8.0#log-automatic-400-responses builder.Services.AddEndpointsApiExplorer(); builder.Services.AddRouting(options => options.LowercaseUrls = true); + var version = Assembly.GetExecutingAssembly().GetName().Version; builder.Services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo + c.SwaggerDoc($"v{version.Major}", new OpenApiInfo { - Title = "Tech Challenge Restaurant API", Version = "v1", Extensions = + Title = "Tech Challenge Restaurant API", Version = $"v{version.Major}.{version.Minor}.{version.Build}", Extensions = { { "x-logo", @@ -107,7 +108,11 @@ public static void Main(string[] args) if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerUI(options => + { + var version = Assembly.GetExecutingAssembly().GetName().Version.Major; + options.SwaggerEndpoint($"/swagger/v{version}/swagger.yaml", $"v{version}"); + }); } app.UseSerilogRequestLogging();