项目类型:asp.net core webapi

1.NuGet安装:Swashbuckle.AspNetCore

2.Startup.cs下的:
ConfigureServices()加入:
services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "Swagger测试接口文档",
                    Description = "this is just a test"

                });

                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath = Path.Combine(basePath, "SwaggerTest.xml");
                c.IncludeXmlComments(xmlPath);

                //  c.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数

            });

asp.net core配置swagger

Configure()加入:
app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "其实,我是一个演员。");
                c.ShowRequestHeaders();

            });

asp.net core配置swagger

3.打开Swagger-UI:http://localhost:64969/swagger/


4.修改默认页面(Peoperties下的lunchSetting.json):

将LunchUrl改为“swagger”

asp.net core配置swagger

相关文章:

  • 2019-12-06
  • 2022-12-23
  • 2021-04-16
  • 2022-12-23
  • 2021-10-05
  • 2018-12-13
  • 2021-12-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
相关资源
相似解决方案