Api/Netina.Api/WebFramework/ScalarUi/ScalarUiConfiguration.cs

44 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

namespace Netina.Api.WebFramework.ScalarUi;
public static class ScalarUiConfiguration
{
public static void MapScalarUi(this IEndpointRouteBuilder app)
{
app.MapGet("/scalar/{documentName}", (string documentName) =>
{
var scalarScript = $$"""
<!doctype html>
<html>
<head>
<title>Scalar API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
</head>
<body>
<!-- Add your own OpenAPI/Swagger specification URL here: -->
<!-- Note: The example is our public proxy (to avoid CORS issues). You can remove the `data-proxy-url` attribute if you dont need it. -->
<script
id="api-reference"
data-url="/swagger/{{documentName}}/swagger.json"></script>
<!-- Optional: You can set a full configuration object like this: -->
<script>
var configuration = {
theme: 'bluePlanet',
}
document.getElementById('api-reference').dataset.configuration =
JSON.stringify(configuration)
</script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
""";
return Results.Content(scalarScript, "text/html");
}).ExcludeFromDescription();
}
}