[backend/openapi] Add scalar-ui, add OpenAPI overview page
This commit is contained in:
parent
01bd71c97d
commit
4186388d4c
4 changed files with 49 additions and 0 deletions
|
@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.Extensions.Configuration.Ini;
|
using Microsoft.Extensions.Configuration.Ini;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Scalar.AspNetCore;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Extensions;
|
namespace Iceshrimp.Backend.Core.Extensions;
|
||||||
|
|
||||||
|
@ -52,6 +53,20 @@ public static class WebApplicationExtensions
|
||||||
options.ConfigObject.AdditionalItems.Add("tagsSorter", "alpha"); // Sort tags alphabetically
|
options.ConfigObject.AdditionalItems.Add("tagsSorter", "alpha"); // Sort tags alphabetically
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.MapScalarApiReference(options =>
|
||||||
|
{
|
||||||
|
options.Title = "Iceshrimp API documentation";
|
||||||
|
options.OpenApiRoutePattern = "/openapi/{documentName}.json";
|
||||||
|
options.EndpointPathPrefix = "/scalar/{documentName}";
|
||||||
|
options.HideModels = true;
|
||||||
|
|
||||||
|
options.CustomCss = """
|
||||||
|
.open-api-client-button, .darklight-reference-promo { display: none !important; }
|
||||||
|
.darklight { height: 14px !important; }
|
||||||
|
.darklight-reference { padding: 14px !important; }
|
||||||
|
""";
|
||||||
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Scalar.AspNetCore" Version="1.2.39" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.4" />
|
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.4" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6-iceshrimp" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6-iceshrimp" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
|
||||||
|
|
25
Iceshrimp.Backend/Pages/OpenApi.razor
Normal file
25
Iceshrimp.Backend/Pages/OpenApi.razor
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
@page "/openapi"
|
||||||
|
@attribute [Route("/scalar")]
|
||||||
|
@using Microsoft.Extensions.Options
|
||||||
|
@using Swashbuckle.AspNetCore.SwaggerGen
|
||||||
|
@inject IOptions<SwaggerGenOptions> Options;
|
||||||
|
|
||||||
|
<h2>OpenAPI definitions</h2>
|
||||||
|
<p>Please select a OpenAPI document below.</p>
|
||||||
|
<table class="auto-table">
|
||||||
|
<thead>
|
||||||
|
<th class="width0">Document</th>
|
||||||
|
<th>Links</th>
|
||||||
|
</thead>
|
||||||
|
@foreach (var doc in Options.Value.SwaggerGeneratorOptions.SwaggerDocs)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@doc.Value.Title</td>
|
||||||
|
<td>
|
||||||
|
<a href="/openapi/@(doc.Key).json">JSON</a> -
|
||||||
|
<a href="/swagger/index.html?urls.primaryName=@(doc.Value.Title)">SwaggerUI</a> -
|
||||||
|
<a href="/scalar/@(doc.Key)">ScalarUI</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
8
Iceshrimp.Backend/Pages/OpenApi.razor.css
Normal file
8
Iceshrimp.Backend/Pages/OpenApi.razor.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.width0 {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auto-table {
|
||||||
|
table-layout: auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue