services.AddSwaggerGen() giving error

后端 未结 4 421
情书的邮戳
情书的邮戳 2021-01-01 10:06

All I\'m trying to do is add swagger to an ASP.Net Core application. I\'m watching a tutorial and all I see them do is add services.AddSwaggerGen(); under the c

4条回答
  •  情歌与酒
    2021-01-01 10:59

    This happens because the implementation of AddSwaggerGen() extension method in ASP.NET Core requires you to provide Action argument which serves as setup action. For example:

    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
    });
    

    You can learn more on how to setup Swagger with ASP.NET Core app here.

    UPDATE: In previous versions they had the AddSwaggerGen() extension method accepting no arguments, but this call was accompanied with call ConfigureSwaggerDocument(Action setupAction). I guess they just got rid of ConfigureSwaggerDocument and added setup action to AddSwaggerGen() method. That being said it seems your tutorial shows how to setup obsolete version of the Swagger.

提交回复
热议问题