diff --git a/Iceshrimp.Backend/Core/Extensions/WebApplicationExtensions.cs b/Iceshrimp.Backend/Core/Extensions/WebApplicationExtensions.cs index 9735e346..79ebf4ef 100644 --- a/Iceshrimp.Backend/Core/Extensions/WebApplicationExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/WebApplicationExtensions.cs @@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.Configuration.Ini; using Microsoft.Extensions.Options; +using Scalar.AspNetCore; namespace Iceshrimp.Backend.Core.Extensions; @@ -52,6 +53,20 @@ public static class WebApplicationExtensions 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; } diff --git a/Iceshrimp.Backend/Iceshrimp.Backend.csproj b/Iceshrimp.Backend/Iceshrimp.Backend.csproj index 1629eb88..e084f20e 100644 --- a/Iceshrimp.Backend/Iceshrimp.Backend.csproj +++ b/Iceshrimp.Backend/Iceshrimp.Backend.csproj @@ -36,6 +36,7 @@ + diff --git a/Iceshrimp.Backend/Pages/OpenApi.razor b/Iceshrimp.Backend/Pages/OpenApi.razor new file mode 100644 index 00000000..64814d99 --- /dev/null +++ b/Iceshrimp.Backend/Pages/OpenApi.razor @@ -0,0 +1,25 @@ +@page "/openapi" +@attribute [Route("/scalar")] +@using Microsoft.Extensions.Options +@using Swashbuckle.AspNetCore.SwaggerGen +@inject IOptions Options; + +

OpenAPI definitions

+

Please select a OpenAPI document below.

+ + + + + + @foreach (var doc in Options.Value.SwaggerGeneratorOptions.SwaggerDocs) + { + + + + + } +
DocumentLinks
@doc.Value.Title + JSON - + SwaggerUI - + ScalarUI +
\ No newline at end of file diff --git a/Iceshrimp.Backend/Pages/OpenApi.razor.css b/Iceshrimp.Backend/Pages/OpenApi.razor.css new file mode 100644 index 00000000..8c9f7a5f --- /dev/null +++ b/Iceshrimp.Backend/Pages/OpenApi.razor.css @@ -0,0 +1,8 @@ +.width0 { + width: 0; +} + +.auto-table { + table-layout: auto; + width: 100%; +} \ No newline at end of file