Skip to content

Commit 017cf4e

Browse files
committed
Move to Scalar
1 parent 99c54d3 commit 017cf4e

File tree

7 files changed

+12
-76
lines changed

7 files changed

+12
-76
lines changed

App/Api/Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<ProjectReference Include="..\Services\Services.csproj" />
44
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />
55
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
6+
<PackageReference Include="Scalar.AspNetCore" />
67
<PackageReference Include="Serilog" />
78
<PackageReference Include="Serilog.Extensions.Hosting" />
89
<PackageReference Include="Serilog.Settings.Configuration" />
910
<PackageReference Include="Serilog.Sinks.Console" />
10-
<PackageReference Include="Swashbuckle.AspNetCore" />
1111
</ItemGroup>
1212
</Project>

App/Api/Setup/ApiMiddleware.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Scalar.AspNetCore;
2+
13
namespace Api.Setup;
24

35
internal static class ApiMiddleware
@@ -13,21 +15,13 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm
1315

1416
app.UseOutputCache();
1517

16-
app.UseStaticFiles();
18+
app.MapOpenApi();
1719

18-
app.UseSwagger();
19-
app.UseSwaggerUI(opt =>
20+
app.MapScalarApiReference(opt =>
2021
{
21-
var descriptions = app.DescribeApiVersions();
22-
foreach (var desc in descriptions)
23-
{
24-
var url = $"/swagger/{desc.GroupName}/swagger.json";
25-
var name = desc.GroupName.ToUpperInvariant();
26-
opt.SwaggerEndpoint(url, name);
27-
}
28-
opt.RoutePrefix = string.Empty;
29-
var indexPath = Path.Combine(environment.WebRootPath, "swagger-ui", "index.html");
30-
opt.IndexStream = () => new FileStream(indexPath, FileMode.Open, FileAccess.Read);
22+
opt.Title = "Bitcoin Web API";
23+
opt.ShowSidebar = true;
24+
opt.DarkMode = true;
3125
});
3226

3327
app.MapHealthChecks("health");
@@ -41,7 +35,6 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm
4135

4236
app.Use(async (context, next) =>
4337
{
44-
context.Response.Headers.Append("Content-Security-Policy", "default-src 'self'");
4538
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
4639
context.Response.Headers.Append("X-Frame-Options", "DENY");
4740
context.Response.Headers.Append("Referrer-Policy", "no-referrer");

App/Api/Setup/ApiServices.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public static void ConfigureServices(this IServiceCollection services)
2828
opt.SubstituteApiVersionInUrl = true;
2929
});
3030

31-
32-
services.AddSwaggerGen();
33-
services.ConfigureOptions<SwaggerOptions>();
31+
services.AddOpenApi();
3432

3533
services.Configure<JsonOptions>(opt =>
3634
{

App/Api/Setup/SwaggerOptions.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

App/Api/wwwroot/swagger-ui/index.html

Lines changed: 0 additions & 19 deletions
This file was deleted.

App/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.4" />
1010
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.4" />
1111
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.4" />
12+
<PackageVersion Include="Scalar.AspNetCore" Version="2.1.11" />
1213
<PackageVersion Include="Serilog" Version="4.2.0" />
1314
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
1415
<PackageVersion Include="Serilog.Settings.Configuration" Version="9.0.0" />
1516
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
1617
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.8.0.113526"/>
17-
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
1818
</ItemGroup>
1919
</Project>

Tests/IntegrationTests/ApiEndpointsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public async Task BuyAndSell(string? fromDate, string? toDate, HttpStatusCode st
6363
}
6464

6565
[Fact]
66-
public async Task Swagger()
66+
public async Task OpenApi()
6767
{
68-
var result = await _fixture.Client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);
68+
var result = await _fixture.Client.GetAsync("/openapi/v1.json", cancellationToken: TestContext.Current.CancellationToken);
6969
result.StatusCode.ShouldBe(HttpStatusCode.OK);
7070
}
7171

0 commit comments

Comments
 (0)