Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions App/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ProjectReference Include="..\Services\Services.csproj" />
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Scalar.AspNetCore" />
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Extensions.Hosting" />
<PackageReference Include="Serilog.Settings.Configuration" />
Expand Down
2 changes: 1 addition & 1 deletion App/Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"hotReloadEnabled": true,
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"launchUrl": "http://localhost:5000/scalar",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HTTP_PORTS": "5000"
Expand Down
29 changes: 16 additions & 13 deletions App/Api/Setup/ApiMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Scalar.AspNetCore;

namespace Api.Setup;

internal static class ApiMiddleware
Expand All @@ -13,21 +15,23 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm

app.UseOutputCache();

app.UseStaticFiles();
app.MapOpenApi("/openapi/{documentName}.json");

app.UseSwagger(opt =>
{
opt.RouteTemplate = "swagger/{documentName}/swagger.json";
});

app.UseSwagger();
app.UseSwaggerUI(opt =>
{
var descriptions = app.DescribeApiVersions();
foreach (var desc in descriptions)
{
var url = $"/swagger/{desc.GroupName}/swagger.json";
var name = desc.GroupName.ToUpperInvariant();
opt.SwaggerEndpoint(url, name);
}
opt.RoutePrefix = string.Empty;
var indexPath = Path.Combine(environment.WebRootPath, "swagger-ui", "index.html");
opt.IndexStream = () => new FileStream(indexPath, FileMode.Open, FileAccess.Read);
opt.RoutePrefix = "swagger";
});

app.MapScalarApiReference(endpointPrefix: "/scalar", opt =>
{
opt.Title = "Bitcoin Web API";
opt.ShowSidebar = true;
opt.DarkMode = true;
});

app.MapHealthChecks("health");
Expand All @@ -41,7 +45,6 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm

app.Use(async (context, next) =>
{
context.Response.Headers.Append("Content-Security-Policy", "default-src 'self'");
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
context.Response.Headers.Append("X-Frame-Options", "DENY");
context.Response.Headers.Append("Referrer-Policy", "no-referrer");
Expand Down
2 changes: 1 addition & 1 deletion App/Api/Setup/ApiServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public static void ConfigureServices(this IServiceCollection services)
opt.SubstituteApiVersionInUrl = true;
});

services.AddOpenApi();

services.AddSwaggerGen();
services.ConfigureOptions<SwaggerOptions>();

services.Configure<JsonOptions>(opt =>
{
Expand Down
36 changes: 0 additions & 36 deletions App/Api/Setup/SwaggerOptions.cs

This file was deleted.

19 changes: 0 additions & 19 deletions App/Api/wwwroot/swagger-ui/index.html

This file was deleted.

1 change: 1 addition & 0 deletions App/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.4" />
<PackageVersion Include="Scalar.AspNetCore" Version="2.1.11" />
<PackageVersion Include="Serilog" Version="4.2.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Serilog.Settings.Configuration" Version="9.0.0" />
Expand Down
11 changes: 9 additions & 2 deletions Tests/IntegrationTests/ApiEndpointsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public async Task BuyAndSell(string? fromDate, string? toDate, HttpStatusCode st
}

[Fact]
public async Task Swagger()
public async Task SwaggerUI()
{
var result = await _fixture.Client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);
var result = await _fixture.Client.GetAsync("/swagger", cancellationToken: TestContext.Current.CancellationToken);
result.StatusCode.ShouldBe(HttpStatusCode.OK);
}

[Fact]
public async Task ScalarUI()
{
var result = await _fixture.Client.GetAsync("/scalar", cancellationToken: TestContext.Current.CancellationToken);
result.StatusCode.ShouldBe(HttpStatusCode.OK);
}

Expand Down