public static void UseSwagger(this IApplicationBuilder app, ISwaggerConfiguration swaggerConfig) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint(swaggerConfig.EndpointUrl, swaggerConfig.EndpointName); }); }
public static void AddSwagger(this IServiceCollection services, ISwaggerConfiguration swaggerConfig) { services.AddSwaggerGen(c => { c.SwaggerDoc( swaggerConfig.Version, new Info { Title = swaggerConfig.DocTitle, Version = swaggerConfig.Version }); }); }
private static void AddJwtAuthentication(SwaggerGenOptions c, ISwaggerConfiguration swaggerConfiguration) { if (!swaggerConfiguration.JWTAuthentication) { return; } c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme (Example: 'Bearer 12345abcdef')", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, BearerFormat = "JWT", Scheme = "Bearer" }); c.OperationFilter <JWTSwaggerSecurityFilter>(); }
public static void UseSwaggerSettings(this IApplicationBuilder app, ISwaggerConfiguration swaggerConfiguration) { if (!swaggerConfiguration.IsEnabled()) { return; } app.UseSwagger(options => { options.RouteTemplate = swaggerConfiguration.JsonRoute; }); app.UseSwaggerUI(opt => { opt.SwaggerEndpoint( swaggerConfiguration.UIEndpoint, swaggerConfiguration.Description ); opt.DocumentTitle = swaggerConfiguration.Title; opt.DefaultModelsExpandDepth(0); opt.RoutePrefix = swaggerConfiguration.RoutePrefix; }); }
public static void AddSwaggerSettings(this IServiceCollection services, ISwaggerConfiguration swaggerConfiguration) { if (!swaggerConfiguration.IsEnabled()) { return; } services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerConfiguration.Version, new OpenApiInfo { Version = swaggerConfiguration.Version, Title = swaggerConfiguration.Title, Description = swaggerConfiguration.Description }); AddJwtAuthentication(c, swaggerConfiguration); var xmlFile = $"{Assembly.GetEntryAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigureSwaggerOptions"/> class. /// </summary> /// <param name="provider">The <see cref="IApiVersionDescriptionProvider">provider</see> used to generate Swagger documents.</param> /// <param name="config">Swagger Configuration from the Settings</param> public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider, ISwaggerConfiguration config) { _provider = provider; _config = config; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// <summary> /// Configures the application using the provided builder, hosting environment, and API version description provider. /// </summary> /// <param name="app">The current application builder.</param> /// <param name="env">The current environment</param> /// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param> /// <param name="swaggerConfig">Swagger Config in Settings (Swagger Plugin)</param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider, ISwaggerConfiguration swaggerConfig) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); //From Swagger Plugin app.AddUseSwagger(provider, swaggerConfig); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); }); }
public static IApplicationBuilder AddUseSwagger(this IApplicationBuilder app, IApiVersionDescriptionProvider provider, ISwaggerConfiguration swaggerConfig) { app.UseSwagger(options => { options.RouteTemplate = swaggerConfig.JsonRoute; }); app.UseSwaggerUI(options => { // build a swagger endpoint for each discovered API version foreach (var description in provider.ApiVersionDescriptions) { options.DocumentTitle = swaggerConfig.PageTitle; options.RoutePrefix = swaggerConfig.RoutePrefix; options.SwaggerEndpoint($"/{swaggerConfig.RoutePrefix}/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant()); } }); return(app); }