Skip to content

Commit

Permalink
projects now use /api/ instead of /swagger/ (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikshafer authored Jun 17, 2024
1 parent 43174ac commit 2f09493
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/Catalog/Catalog.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Catalog.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5252;https://localhost:5253",
"launchUrl": "swagger",
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
12 changes: 10 additions & 2 deletions src/Inventory/Inventory.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Inventory/Inventory.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:7024;https://localhost:5155",
"launchUrl": "swagger",
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
3 changes: 3 additions & 0 deletions src/Legacy/Legacy.Api/Legacy.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.6" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.1" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 32 additions & 4 deletions src/Legacy/Legacy.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/Legacy/Legacy.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions src/Pricing/Discounts.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Pricing/Discounts.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions src/Pricing/Prices.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Pricing/Prices.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2f09493

Please sign in to comment.