internal static IServiceCollection ConfigureSwaggerGenerator(this IServiceCollection services, Configurations.App.WebApiConfiguration webApiConfiguration, Configurations.Security.AuthorityConfiguration authorityConfiguration, Configurations.Swagger.SwaggerUIConfiguration swaggerConfiguration) { Log.Information("{method}", nameof(ConfigureSwaggerGenerator)); services.AddSwaggerGen(setupAction => { setupAction.SwaggerDoc(webApiConfiguration.WebApiVersion, new Microsoft.OpenApi.Models.OpenApiInfo { Contact = new Microsoft.OpenApi.Models.OpenApiContact { Name = webApiConfiguration.WebApiContactName, Email = webApiConfiguration.WebApiContactMail, Url = new Uri(webApiConfiguration.WebApiContactUrl) }, Title = webApiConfiguration.WebApiTitle, Version = webApiConfiguration.WebApiVersion, Description = webApiConfiguration.WebApiDescription }); setupAction.IncludeXmlComments(System.IO.Path.Combine(AppContext.BaseDirectory, $"{webApiConfiguration.GetType().Assembly.GetName().Name}.xml")); setupAction.AddSecurityDefinition("OAuth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme { Type = Microsoft.OpenApi.Models.SecuritySchemeType.OAuth2, Flows = new Microsoft.OpenApi.Models.OpenApiOAuthFlows { AuthorizationCode = new Microsoft.OpenApi.Models.OpenApiOAuthFlow { AuthorizationUrl = new Uri($"{authorityConfiguration.Authority}/connect/authorize"), TokenUrl = new Uri($"{authorityConfiguration.Authority}/connect/token"), Scopes = new Dictionary <string, string> { { swaggerConfiguration.SwaggerUITargetApiScope, swaggerConfiguration.SwaggerUITargetApiScopeTitle } } } }, Description = "Swagger Generator OpenId security scheme." }); setupAction.OperationFilter <Configurations.Authorization.AuthorizeCheckOperationFilter>(); }); return(services); }
internal static IServiceCollection AddSwaggerConfiguration(this IServiceCollection services, IConfiguration configuration, out Configurations.Swagger.SwaggerUIConfiguration swaggerConfigration) { Log.Information("{method}", nameof(AddSwaggerConfiguration)); swaggerConfigration = configuration.GetSection(nameof(Configurations.Swagger.SwaggerUIConfiguration)).Get <Configurations.Swagger.SwaggerUIConfiguration>(); return(services.AddSingleton(swaggerConfigration)); }