How to use Swagger Codegen with .net core

天大地大妈咪最大 提交于 2019-12-04 23:20:36

问题


I am able to integrate the Swagge UI in my web api using Swashbuckle. I also want to explore the swagger codegen feature. Can somebody help in - how I can integrate swagger codegen into my web api project? Or do I need to download any tool? I want to be able it to host the codegen and pass the json/raml form specs to generate client in .net core.

I am not able to find enough docs on above.

EDIT : I want to know how I can host codegen in my WEBAPI.

Thanks!


回答1:


You should install "Swashbuckle.AspNetCore.Swagger" nuget package by right click your project and click manage nuget packages.

Then you should add these codes into your project startup place eg. Program.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    // Register the Swagger generator, defining one or more Swagger documents
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
    });
}

public void Configure(IApplicationBuilder app)
{
    // Enable middleware to serve generated Swagger as a JSON endpoint.
    app.UseSwagger();

    app.UseMvc();
}


来源:https://stackoverflow.com/questions/48539606/how-to-use-swagger-codegen-with-net-core

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