As probably most people in the .NET ecosystem I’m using Swashbuckle to generate my OpenAPI documentation. (Anyone using NSwag instead?)
After upgrading to ASP.NET Core 3.0 (and switching to the 5.0-rc4 prerelease version of Swashbuckle), the following code no longer compiled:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<TodoContext>(opt => | |
opt.UseInMemoryDatabase("TodoList")); | |
services.AddControllers(); | |
// Register the Swagger generator, defining 1 or more Swagger documents | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); | |
}); | |
} |
I had to replace the Info class which couldn’t be found by the OpenApiInfo class:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<TodoContext>(opt => | |
opt.UseInMemoryDatabase("TodoList")); | |
services.AddControllers(); | |
// Register the Swagger generator, defining 1 or more Swagger documents | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); | |
}); | |
} |
This OpenApiInfo class is now part of the Microsoft.OpenApi.Models namespace.