public static IServiceCollection AddSwagger(this IServiceCollection services) { return(services.AddSwaggerGen(options => { //options.SwaggerDoc("v1", new OpenApiInfo //{ // Version = "1.0.0", // Title = "我的接口", // Description = "接口描述" //}); ApiInfos.ForEach(x => { options.SwaggerDoc(x.UrlPrefix, x.OpenApiInfo); }); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyBlog.HttpApi.xml")); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyBlog.Domain.xml")); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyBlog.Application.Contracts.xml")); options.DocumentFilter <SwaggerDocumentFilter>(); // 开启JWT var security = new OpenApiSecurityScheme { Description = "JWT模式授权,请输入Bearer{Token}进行身份验证", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }; options.AddSecurityDefinition("oauth2", security); options.AddSecurityRequirement(new OpenApiSecurityRequirement { { security, new List <string>() } }); options.OperationFilter <AddResponseHeadersFilter>(); options.OperationFilter <AppendAuthorizeToSummaryOperationFilter>(); options.OperationFilter <SecurityRequirementsOperationFilter>(); })); }
public static IServiceCollection AddSwagger(this IServiceCollection services) { return(services.AddSwaggerGen(options => { ApiInfos.ForEach(x => { options.SwaggerDoc(x.UrlPrefix, x.OpenApiInfo); }); var security = new OpenApiSecurityScheme { Description = "JWT模式授权,请输入 Bearer {Token} 进行身份验证", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }; options.AddSecurityDefinition("oauth2", security); options.AddSecurityRequirement(new OpenApiSecurityRequirement { { security, new List <string>() } }); options.OperationFilter <AddResponseHeadersFilter>(); options.OperationFilter <AppendAuthorizeToSummaryOperationFilter>(); options.OperationFilter <SecurityRequirementsOperationFilter>(); options.ResolveConflictingActions(x => x.First()); })); }
public static void UseSwaggerUI(this IApplicationBuilder app) { app.UseSwaggerUI(options => { //options.SwaggerEndpoint($"/swagger/v1/swagger.json", "默认接口"); // 遍历分组信息,生成Json ApiInfos.ForEach(x => { options.SwaggerEndpoint($"/swagger/{x.UrlPrefix}/swagger.json", x.Name); }); options.DefaultModelsExpandDepth(-1); options.DocExpansion(DocExpansion.List); options.RoutePrefix = string.Empty; options.DocumentTitle = "😍接口文档----程序猿贝塔"; }); }
public static void UseSwaggerUI(this IApplicationBuilder app) { app.UseSwaggerUI(options => { ApiInfos.ForEach(x => { options.SwaggerEndpoint($"/swagger/{x.UrlPrefix}/swagger.json", x.Name); }); // 模型的默认扩展深度,设置为 -1 完全隐藏模型 options.DefaultModelsExpandDepth(-1); // API文档仅展开标记 options.DocExpansion(DocExpansion.List); // API前缀设置为空 options.RoutePrefix = string.Empty; // API页面Title options.DocumentTitle = "接口文档"; }); }