You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swashbuckle version 6.4 and 6.5 (didn't test others).
Generate a new minimal api project
add await app.Services.GetRequiredService<IAsyncSwaggerProvider>().GetSwaggerAsync("v1"); just before app.Run() in program.cs
Weather api does not show up in swagger
now the default weather api doesn't show up in swagger. Here's a full copy of the source:
using Swashbuckle.AspNetCore.Swagger;varbuilder= WebApplication.CreateBuilder(args);// Add services to the container.// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();varapp= builder.Build();// Configure the HTTP request pipeline.if(app.Environment.IsDevelopment()){
app.UseSwagger();
app.UseSwaggerUI();}
app.UseHttpsRedirection();varsummaries=new[]{"Freezing","Bracing","Chilly","Cool","Mild","Warm","Balmy","Hot","Sweltering","Scorching"};
app.UseRouting();
app.MapGet("/weatherforecast",()=>{varforecast= Enumerable.Range(1,5).Select(index =>new WeatherForecast( DateOnly.FromDateTime(DateTime.Now.AddDays(index)), Random.Shared.Next(-20,55), summaries[Random.Shared.Next(summaries.Length)])).ToArray();returnforecast;}).WithName("GetWeatherForecast").WithOpenApi();await app.Services.GetRequiredService<IAsyncSwaggerProvider>().GetSwaggerAsync("v1");
app.Run();publicrecordWeatherForecast(DateOnlyDate,intTemperatureC,string?Summary){publicintTemperatureF=>32+(int)(TemperatureC/0.5556);}
it seems like there's a race condition with calling GetSwaggerAsync too early where the minimal apis don't show up. MVC Controllers will show up correctly. The reason I'm doing this is to validate that we can generate a swagger doc on startup when devs are working. In my case I put it in a service and called generate after a 5 second delay to work around the issue.
The text was updated successfully, but these errors were encountered:
Swashbuckle version 6.4 and 6.5 (didn't test others).
await app.Services.GetRequiredService<IAsyncSwaggerProvider>().GetSwaggerAsync("v1");
just beforeapp.Run()
in program.csnow the default weather api doesn't show up in swagger. Here's a full copy of the source:
it seems like there's a race condition with calling
GetSwaggerAsync
too early where the minimal apis don't show up. MVC Controllers will show up correctly. The reason I'm doing this is to validate that we can generate a swagger doc on startup when devs are working. In my case I put it in a service and called generate after a 5 second delay to work around the issue.The text was updated successfully, but these errors were encountered: