问题
I'm getting this error when tryign to run swashbuckle. Any ideas?
I have this in my ConfigureServices Class
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "testing",
Version = "v1" });
});
And this in my Configure Class
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
回答1:
I ran into this same issue today. After looking at the Microsoft documentation, it appears that SwaggerDoc
is looking for a string and an Info
parameter. At the top of your file make sure that you include using Swashbuckle.AspNetCore.Swagger;
and replace OpenApiInfo
with Info
.
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "testing",
Version = "v1" });
});
回答2:
Before Swashbuckle.AspNetCore version 5.0.0 (which is not yet released, on november 2019), SwaggerDoc extension method requires a Swashbuckle.AspNetCore.Swagger.Info
parameter. So, you have to write :
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
Especially, if you are coming from : Get started with Swashbuckle and ASP.NET Core
Beginning with version 5.0.0, SwaggerDoc extension method now requires a Microsoft.OpenApi.Models.OpenApiInfo
parameter.
来源:https://stackoverflow.com/questions/57080588/cannot-convert-from-microsoft-openapi-models-openapiinfo-to-swashbuckle-aspne