public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> { readonly IApiVersionDescriptionProvider provider;
public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) => this.provider = provider;
public void Configure(SwaggerGenOptions options) { foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, new OpenApiInfo { Description = $"Demo API {description.ApiVersion} Description", Version = description.ApiVersion.ToString(), Title = $"Demo API 文档{description.ApiVersion}", Contact = new OpenApiContact() { Name = "eyiadmin", Email = "188781475@qq.com" }, License = new OpenApiLicense { Name = "Apache 2.0", Url = new Uri("http://www.apache.org/licenses/LICENSE-2.0.html") } }); }
var docXmlPath = Path.Combine(AppContext.BaseDirectory, "Web.xml"); options.IncludeXmlComments(docXmlPath); } }
options.AddSecurityDefinition("bearer", new OpenApiSecurityScheme { Type = SecuritySchemeType.Http, In = ParameterLocation.Header, Name = "Authorization", Scheme = "bearer", BearerFormat = "JWT", Description = "JWT Authorization header using the Bearer scheme.", }); var req = new OpenApiSecurityRequirement(); req.Add(new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "bearer" }