欢迎来到我的的博客园,祝大家学有所成,早点实现自己的人生理想。

使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档

一、问题

  使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档的方法

二、解决方案

  参考文章:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio

  1、Install-Package Swashbuckle.AspNetCore

  2、在ConfigureServices中添加AddSwaggerGen。

复制代码
public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoList"));
    services.AddMvc();

    // Register the Swagger generator, defining one or more Swagger documents
      services.AddSwaggerGen(options =>
      {
                //options.DescribeAllEnumsAsStrings();
                options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Title = "Azure Adapter Api - Catalog HTTP API",
                    Version = "v1",
                    Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample",
                    TermsOfService = "Terms Of Service"
               });
      });
}
复制代码

  3、在Configure中添加

            app.UseSwagger().UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

三、运行测试:

  输入 http://127.0.0.1:8080/swagger/  或者 http://127.0.0.1:8080/swagger/v1/swagger.json

  

 

posted @   宋兴柱  阅读(2187)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示