From def41a9f304b44bc6b295fe4914fbef5f3051f59 Mon Sep 17 00:00:00 2001 From: Kyle Kienapfel Date: Fri, 18 Apr 2025 10:42:11 -0700 Subject: [PATCH] Show multiple versions in scalar viewer in a quirky manner So for whatever reason, the routing really doesn't like the idea of routing to a single field, like /favicon.ico or /scalar To work around this, I propose we add some additional routing so that we can access the API documentation at /scalar/viewer so that users can go there and then choose which version of the API they wish to view --- API/Program.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/API/Program.cs b/API/Program.cs index 940eb2e9..ab3a47fd 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -97,7 +97,14 @@ app.MapHub("/1/hubs/user", options => options.Transports = HttpTransportType.WebSockets); app.MapHub("/1/hubs/share/link/{id:guid}", options => options.Transports = HttpTransportType.WebSockets); -app.MapScalarApiReference(options => options.OpenApiRoutePattern = "/swagger/{documentName}/swagger.json"); +Action scalarOptions = options => + options + .WithOpenApiRoutePattern("/swagger/{documentName}/swagger.json") + .AddDocument("1", "Version 1") + .AddDocument("2", "Version 2"); +app.MapScalarApiReference("/scalar/viewer", scalarOptions); +// Routing for /scalar, E.g: /scalar/1 and /scalar/2 +app.MapScalarApiReference(scalarOptions); app.Run();