/// <summary> /// Adds Swagger service to the IServiceCollection and configure it /// </summary> /// <param name="services"></param> /// <param name="swaggerConfig"></param> /// <returns></returns> public static IServiceCollection AddSwagger(this IServiceCollection services, SwaggerConfig swaggerConfig) { return(services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerConfig.Version, new Info { Title = swaggerConfig.ApplicationName, Version = swaggerConfig.Version }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[] { } } }); // Set the comments path for the Swagger JSON and UI. var xmlFile = swaggerConfig.XmlFile; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); })); }
/// <summary> /// Adds Swagger service to the IServiceCollection and configure it /// </summary> /// <param name="services"></param> /// <param name="swaggerConfig"></param> /// <returns></returns> public static IServiceCollection AddSwagger(this IServiceCollection services, SwaggerConfig swaggerConfig) => services.AddSwaggerGen(options => { options.SwaggerDoc(swaggerConfig.Version, new OpenApiInfo { Title = swaggerConfig.ApplicationName, Version = swaggerConfig.Version }); options.DocumentFilter <DocumentFilterAddHealth>(); AddSecurityDefinition(options); AddSecurityRequirement(options); SetDocumentPath(swaggerConfig, options); });
/// <summary> /// Adds Swagger service to the IServiceCollection and configure it /// </summary> /// <param name="services"></param> /// <param name="swaggerConfig"></param> /// <returns></returns> public static IServiceCollection AddSwagger(this IServiceCollection services, SwaggerConfig swaggerConfig) => services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerConfig.Version, new OpenApiInfo { Title = swaggerConfig.ApplicationName, Version = swaggerConfig.Version }); c.DocumentFilter <DocumentFilterAddHealth>(); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() { Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Description = "Please insert JWT with Bearer into field", }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }, }, new[] { "readAccess", "writeAccess" } }, }); // Set the comments path for the Swagger JSON and UI. var xmlFile = swaggerConfig.XmlFile; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); });