Skip to content

Commit

Permalink
feat: scalar integration (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
SulliNV authored Dec 2, 2024
1 parent c101d8c commit 8bcd90a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions template/src/Placeholder.ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Configure the HTTP request pipeline.
app.UseExceptionHandler();

app.ConfigureOpenApi();
app.MapWeatherEndpoints();
app.MapDefaultEndpoints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:7587",
"launchUrl": "http://localhost:7587/scalar/v1",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true",
Expand Down
19 changes: 19 additions & 0 deletions template/src/Placeholder.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Scalar.AspNetCore;

namespace Microsoft.Extensions.Hosting;

Expand All @@ -31,6 +32,8 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddServiceDiscovery();
});

builder.Services.AddOpenApi();

return builder;
}

Expand Down Expand Up @@ -108,4 +111,20 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)

return app;
}

public static WebApplication ConfigureOpenApi(this WebApplication app)
{
if (!app.Environment.IsProduction())
{
app.MapOpenApi();
app.MapScalarApiReference(options =>
{
// This is necessary to ensure consistent API url mapping between the Scalar UI and the browser
// See comments in https://dev.azure.com/nventive/Practice%20committees/_workitems/edit/305140 for more information
options.Servers = Array.Empty<ScalarServer>();
});
}

return app;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0-rc.1.24511.1" />
Expand All @@ -17,6 +18,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.42" />
</ItemGroup>

</Project>

0 comments on commit 8bcd90a

Please sign in to comment.