Skip to content

Commit a93ce72

Browse files
committed
Move to using Scalar
1 parent b43539c commit a93ce72

File tree

7 files changed

+12
-74
lines changed

7 files changed

+12
-74
lines changed

App/Api/Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
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.Sinks.Console" />
9-
<PackageReference Include="Swashbuckle.AspNetCore" />
1010
</ItemGroup>
1111
</Project>

App/Api/Setup/Middleware.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Scalar.AspNetCore;
2+
13
public static class Middleware
24
{
35
public static void ConfigureMiddleware(this WebApplication app)
@@ -13,21 +15,12 @@ public static void ConfigureMiddleware(this WebApplication app)
1315

1416
app.UseOutputCache();
1517

16-
app.UseStaticFiles();
17-
18-
app.UseSwagger();
19-
app.UseSwaggerUI(opt =>
18+
app.MapOpenApi();
19+
app.MapScalarApiReference(opt =>
2020
{
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(env.WebRootPath, "swagger-ui", "index.html");
30-
opt.IndexStream = () => new FileStream(indexPath, FileMode.Open, FileAccess.Read);
21+
opt.Title = "Bitcoin Web API";
22+
opt.ShowSidebar = true;
23+
opt.DarkMode = true;
3124
});
3225

3326
app.MapHealthChecks("health");
@@ -41,7 +34,6 @@ public static void ConfigureMiddleware(this WebApplication app)
4134

4235
app.Use(async (context, next) =>
4336
{
44-
context.Response.Headers.Append("Content-Security-Policy", "default-src 'self'");
4537
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
4638
context.Response.Headers.Append("X-Frame-Options", "DENY");
4739
context.Response.Headers.Append("Referrer-Policy", "no-referrer");

App/Api/Setup/Services.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public static void ConfigureServices(this IServiceCollection services)
2525
opt.SubstituteApiVersionInUrl = true;
2626
});
2727

28-
services.AddSwaggerGen();
29-
services.ConfigureOptions<ConfigureSwaggerOptions>();
28+
services.AddOpenApi();
3029

3130
services.Configure<JsonOptions>(opt =>
3231
{

App/Api/Setup/Swagger.cs

Lines changed: 0 additions & 34 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
@@ -6,9 +6,9 @@
66
<PackageVersion Include="Asp.Versioning.Http" Version="8.1.0" />
77
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
88
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
9+
<PackageVersion Include="Scalar.AspNetCore" Version="1.2.41" />
910
<PackageVersion Include="Serilog" Version="4.1.0" />
1011
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
1112
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
12-
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.0.0" />
1313
</ItemGroup>
1414
</Project>

Tests/IntegrationTests/IntegrationTests.cs

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

4242
[Fact]
43-
public async Task Swagger()
43+
public async Task OpenApi()
4444
{
45-
var result = await _fixture.Client.GetAsync("/");
45+
var result = await _fixture.Client.GetAsync("/openapi/v1.json");
4646
result.StatusCode.Should().Be(HttpStatusCode.OK);
4747
}
4848

0 commit comments

Comments
 (0)