NET核心如何使用Swagger Codegen [英] How to use Swagger Codegen with .net core

查看:117
本文介绍了NET核心如何使用Swagger Codegen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Swashbuckle将Swagge UI集成到我的Web api中。我也想探索swagger代码生成功能。有人可以帮忙吗-我如何将swagger代码生成集成到我的Web api项目中?还是我需要下载任何工具?我希望它能够托管代码生成器并通过json / raml表单规范以在.net核心中生成客户端。

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.

编辑:我想知道如何在我的WEBAPI中托管代码源。

谢谢!

推荐答案

您应该安装 Swashbuckle.AspNetCore.Swagger nuget软件包,方法是右键单击您的项目,然后单击管理nuget软件包。

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

然后,您应该将这些代码添加到项目的启动位置,例如。 Program.cs

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();
}

这篇关于NET核心如何使用Swagger Codegen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆