using Microsoft.OpenApi.Models; namespace Newsbot.Collector.Api.Startup; public static class SwaggerStartup { public static void ConfigureSwagger(IServiceCollection services) { // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); // Configure swagger authentication services.AddSwaggerGen(cfg => { cfg.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme { Description = "The API key to access the API", Type = SecuritySchemeType.ApiKey, Name = "x-api-key", In = ParameterLocation.Header, Scheme = "ApiKeyScheme" }); cfg.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization Header using the bearer scheme", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); cfg.AddSecurityRequirement(new OpenApiSecurityRequirement { //{ // new OpenApiSecurityScheme // { // Reference = new OpenApiReference // { // Type = ReferenceType.SecurityScheme, // Id = "ApiKey" // }, // In = ParameterLocation.Header // }, // new List() //}, { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header }, new List() } }); }); } }