添加小绿锁,Nuget包下载Swashbuckle.AspNetCore.Filters,在
扩展方法AddSwagger(this IServiceCollection services)
中调用。
public static IServiceCollection AddSwagger(this IServiceCollection services){return services.AddSwaggerGen(options =>{...var security = new OpenApiSecurityScheme{Description = "JWT模式授权,请输入 Bearer {Token} 进行身份验证",Name = "Authorization",In = ParameterLocation.Header,Type = SecuritySchemeType.ApiKey};options.AddSecurityDefinition("oauth2", security);options.AddSecurityRequirement(new OpenApiSecurityRequirement { { security, new List<string>() } });options.OperationFilter<AddResponseHeadersFilter>();