cannot convert from 'Microsoft.OpenApi.Models.OpenApiInfo' to 'Swashbuckle.AspNetCore.Swagger.Info'

淺唱寂寞╮ 提交于 2019-12-19 17:45:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!