From 2f094932124c8e42f6da66ab52907c25ef42f079 Mon Sep 17 00:00:00 2001 From: Erik Shafer Date: Mon, 17 Jun 2024 00:29:47 -0500 Subject: [PATCH] projects now use `/api/` instead of `/swagger/` (#38) --- src/Catalog/Catalog.Api/Program.cs | 10 +++++- .../Properties/launchSettings.json | 2 +- src/Inventory/Inventory.Api/Program.cs | 12 +++++-- .../Properties/launchSettings.json | 2 +- src/Legacy/Legacy.Api/Legacy.Api.csproj | 3 ++ src/Legacy/Legacy.Api/Program.cs | 36 ++++++++++++++++--- .../Legacy.Api/Properties/launchSettings.json | 2 +- src/Pricing/Discounts.Api/Program.cs | 11 ++++-- .../Properties/launchSettings.json | 2 +- src/Pricing/Prices.Api/Program.cs | 11 ++++-- .../Prices.Api/Properties/launchSettings.json | 2 +- 11 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/Catalog/Catalog.Api/Program.cs b/src/Catalog/Catalog.Api/Program.cs index ae8d143..f5cc915 100644 --- a/src/Catalog/Catalog.Api/Program.cs +++ b/src/Catalog/Catalog.Api/Program.cs @@ -28,7 +28,15 @@ var app = builder.Build(); -app.UseSwagger().UseSwaggerUI(); +app.UseSwagger(opts => + { + opts.RouteTemplate = "api/{documentName}/swagger.json"; + }) + .UseSwaggerUI(opts => + { + opts.SwaggerEndpoint("/api/v1/swagger.json", "Catalog API"); + opts.RoutePrefix = "api"; + }); app.UseSerilogRequestLogging(); app.MapControllers(); app.UseOpenTelemetryPrometheusScrapingEndpoint(); diff --git a/src/Catalog/Catalog.Api/Properties/launchSettings.json b/src/Catalog/Catalog.Api/Properties/launchSettings.json index 0478a19..6e7a166 100644 --- a/src/Catalog/Catalog.Api/Properties/launchSettings.json +++ b/src/Catalog/Catalog.Api/Properties/launchSettings.json @@ -5,7 +5,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:5252;https://localhost:5253", - "launchUrl": "swagger", + "launchUrl": "api", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/Inventory/Inventory.Api/Program.cs b/src/Inventory/Inventory.Api/Program.cs index 1f771a0..71cb929 100644 --- a/src/Inventory/Inventory.Api/Program.cs +++ b/src/Inventory/Inventory.Api/Program.cs @@ -30,8 +30,16 @@ if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app + .UseSwagger(opts => + { + opts.RouteTemplate = "api/{documentName}/swagger.json"; + }) + .UseSwaggerUI(opts => + { + opts.SwaggerEndpoint("/api/v1/swagger.json", "Legacy API"); + opts.RoutePrefix = "api"; + }); } // app.UseHttpsRedirection(); diff --git a/src/Inventory/Inventory.Api/Properties/launchSettings.json b/src/Inventory/Inventory.Api/Properties/launchSettings.json index 12c9b66..830e8a5 100644 --- a/src/Inventory/Inventory.Api/Properties/launchSettings.json +++ b/src/Inventory/Inventory.Api/Properties/launchSettings.json @@ -5,7 +5,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:7024;https://localhost:5155", - "launchUrl": "swagger", + "launchUrl": "api", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/Legacy/Legacy.Api/Legacy.Api.csproj b/src/Legacy/Legacy.Api/Legacy.Api.csproj index c1e0592..d8d0866 100644 --- a/src/Legacy/Legacy.Api/Legacy.Api.csproj +++ b/src/Legacy/Legacy.Api/Legacy.Api.csproj @@ -6,7 +6,10 @@ + + + diff --git a/src/Legacy/Legacy.Api/Program.cs b/src/Legacy/Legacy.Api/Program.cs index e694636..6c55e6b 100644 --- a/src/Legacy/Legacy.Api/Program.cs +++ b/src/Legacy/Legacy.Api/Program.cs @@ -2,6 +2,10 @@ using Legacy.Data.DbContexts; using Legacy.Data.Seeds; using Microsoft.EntityFrameworkCore; +using OpenTelemetry.Logs; +using OpenTelemetry.Metrics; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; var builder = WebApplication.CreateBuilder(args); @@ -11,19 +15,43 @@ .AddEndpointsApiExplorer() .AddControllers(); +const string serviceName = "legacy-api"; + +builder.Logging.AddOpenTelemetry(options => +{ + options + .SetResourceBuilder( + ResourceBuilder.CreateDefault() + .AddService(serviceName)) + .AddConsoleExporter(); +}); +builder.Services.AddOpenTelemetry() + .ConfigureResource(resource => resource.AddService(serviceName)) + .WithTracing(tracing => tracing + .AddAspNetCoreInstrumentation() + .AddConsoleExporter()) + .WithMetrics(metrics => metrics + .AddAspNetCoreInstrumentation() + .AddConsoleExporter()); + var app = builder.Build(); app - .UseSwagger() - .UseSwaggerUI() + .UseSwagger(opts => + { + opts.RouteTemplate = "api/{documentName}/swagger.json"; + }) + .UseSwaggerUI(opts => + { + opts.SwaggerEndpoint("/api/v1/swagger.json", "Legacy API"); + opts.RoutePrefix = "api"; + }) .UseRouting() .UseEndpoints(endpoints => { endpoints.MapControllers(); }); -app.MapGet("/", () => "Hello World!"); - // if(app.Environment.IsDevelopment()) using var scope = app.Services.CreateScope(); diff --git a/src/Legacy/Legacy.Api/Properties/launchSettings.json b/src/Legacy/Legacy.Api/Properties/launchSettings.json index 4273fcd..f5bf0e2 100644 --- a/src/Legacy/Legacy.Api/Properties/launchSettings.json +++ b/src/Legacy/Legacy.Api/Properties/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "api", "applicationUrl": "http://localhost:5254;https://localhost:5255", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/src/Pricing/Discounts.Api/Program.cs b/src/Pricing/Discounts.Api/Program.cs index 27fd312..a60870b 100644 --- a/src/Pricing/Discounts.Api/Program.cs +++ b/src/Pricing/Discounts.Api/Program.cs @@ -37,8 +37,15 @@ if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwagger(opts => + { + opts.RouteTemplate = "api/{documentName}/swagger.json"; + }) + .UseSwaggerUI(opts => + { + opts.SwaggerEndpoint("/api/v1/swagger.json", "Discounts API"); + opts.RoutePrefix = "api"; + }); } // app.UseHttpsRedirection(); diff --git a/src/Pricing/Discounts.Api/Properties/launchSettings.json b/src/Pricing/Discounts.Api/Properties/launchSettings.json index 953e2d0..6793f59 100644 --- a/src/Pricing/Discounts.Api/Properties/launchSettings.json +++ b/src/Pricing/Discounts.Api/Properties/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "api", "applicationUrl": "http://localhost:5220;https://localhost:5221", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/src/Pricing/Prices.Api/Program.cs b/src/Pricing/Prices.Api/Program.cs index 503ee27..6294b77 100644 --- a/src/Pricing/Prices.Api/Program.cs +++ b/src/Pricing/Prices.Api/Program.cs @@ -30,8 +30,15 @@ if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwagger(opts => + { + opts.RouteTemplate = "api/{documentName}/swagger.json"; + }) + .UseSwaggerUI(opts => + { + opts.SwaggerEndpoint("/api/v1/swagger.json", "Prices API"); + opts.RoutePrefix = "api"; + }); } // app.UseHttpsRedirection(); diff --git a/src/Pricing/Prices.Api/Properties/launchSettings.json b/src/Pricing/Prices.Api/Properties/launchSettings.json index 06f9928..5328847 100644 --- a/src/Pricing/Prices.Api/Properties/launchSettings.json +++ b/src/Pricing/Prices.Api/Properties/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "api", "applicationUrl": "http://localhost:5218;https://localhost:5219", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development"