Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Created November 26, 2025 15:30
Show Gist options
  • Select an option

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

Select an option

Save gistlyn/494a1def5aa9cfa47bfb2fb9d46ca353 to your computer and use it in GitHub Desktop.
openapi3
dotnet add package Microsoft.AspNetCore.OpenApi
dotnet add package Swashbuckle.AspNetCore
dotnet add package ServiceStack.AspNetCore.OpenApi
using Scalar.AspNetCore;
using ServiceStack;
[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))]
namespace MyApp;
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