(精华)2020年7月22日 ASP.NET Core Swagger的使用(NSwag工具版)

首先安装包

Install-Package NSwag.AspNetCore
public void ConfigureServices(IServiceCollection services)
{
   //swagger
	services.AddOpenApiDocument(settings =>
	{
	    settings.AddSecurity("身份认证Token", Enumerable.Empty<string>(), new OpenApiSecurityScheme()
	    {
	        Scheme = "bearer",
	        Description = "Authorization:Bearer {your JWT token}<br/><b>授权地址:/Base_Manage/Home/SubmitLogin</b>",
	        Name = "Authorization",
	        In = OpenApiSecurityApiKeyLocation.Header,
	        Type = OpenApiSecuritySchemeType.Http
	    });
	});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
   app.UseOpenApi(); //添加swagger生成api文档(默认路由文档 /swagger/v1/swagger.json)
   app.UseSwaggerUi3();//添加Swagger UI到请求管道中(默认路由: /swagger).
}
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:上身试试 返回首页