Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active November 29, 2025 10:54
Show Gist options
  • Select an option

  • Save gistlyn/dac47b68e77796902cde0f0b7b9c6ac2 to your computer and use it in GitHub Desktop.

Select an option

Save gistlyn/dac47b68e77796902cde0f0b7b9c6ac2 to your computer and use it in GitHub Desktop.
openapi3
dotnet add package Scalar.AspNetCore
dotnet add package ServiceStack.OpenApi.Microsoft
using Scalar.AspNetCore;
using ServiceStack;
[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))]
namespace MyApp;
//TODO: Fix build error by adding to <PropertyGroup> https://github.com/dotnet/roslyn/issues/74511
// <InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.AspNetCore.OpenApi.Generated</InterceptorsNamespaces>
public class ConfigureOpenApi : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
if (context.HostingEnvironment.IsDevelopment())
{
services.AddOpenApi();
services.AddServiceStackOpenApi();
// services.AddBasicAuth<Data.ApplicationUser>();
// services.AddApiKeys();
// services.AddJwtAuth();
services.AddTransient<IStartupFilter,StartupFilter>();
}
});
public class StartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) => app =>
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapOpenApi();
endpoints.MapScalarApiReference();
});
next(app);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment