Commit 2c602f14 by wyc

SwaggerOpen

parent a7e048c2
......@@ -10,32 +10,34 @@ namespace Performance.Api.Configurations
{
public static class SwaggerConfig
{
public static void AddSwaggerConfiguration(this IServiceCollection services)
public static void AddSwaggerConfiguration(this IServiceCollection services, IConfiguration configuration)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddSwaggerGen(c =>
if (configuration.GetValue("SwaggerOpen", true))
{
c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1.0", Title = "绩效API接口" });
if (services == null) throw new ArgumentNullException(nameof(services));
var xmlPath = new string[]
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1.0", Title = "绩效API接口" });
var xmlPath = new string[]
{
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.Api.xml"),
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.DtoModels.xml"),
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.EntityModels.xml"),
};
};
foreach (var item in xmlPath)
{
c.IncludeXmlComments(item, true);
}
foreach (var item in xmlPath)
{
c.IncludeXmlComments(item, true);
}
//var xmlPathsss = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.Api.xml");
//c.IncludeXmlComments(xmlPathsss, true);
//var xmlPathsss = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.Api.xml");
//c.IncludeXmlComments(xmlPathsss, true);
// Token绑定到ConfigureServices
var security = new OpenApiSecurityRequirement
{
// Token绑定到ConfigureServices
var security = new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
......@@ -43,28 +45,30 @@ public static void AddSwaggerConfiguration(this IServiceCollection services)
},
new List<string>()
}
};
c.AddSecurityRequirement(security);
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)",
Name = "Authorization",
In = ParameterLocation.Header
};
c.AddSecurityRequirement(security);
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)",
Name = "Authorization",
In = ParameterLocation.Header
});
});
});
}
}
public static void UseSwaggerSetup(this IApplicationBuilder app, IConfiguration configuration)
{
if (app == null) throw new ArgumentNullException(nameof(app));
app.UseSwagger();
app.UseSwaggerUI(c =>
if (configuration.GetValue("SwaggerOpen", true))
{
c.SwaggerEndpoint(configuration["Application:SwaggerEndpoint"], "v1.0");
c.RoutePrefix = string.Empty;
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint(configuration["Application:SwaggerEndpoint"], "v1.0");
c.RoutePrefix = string.Empty;
});
}
}
}
}
......@@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddAutoMapperConfiguration();
// swagger
services.AddSwaggerConfiguration();
services.AddSwaggerConfiguration(Configuration);
// service repository
services.AddDependencyInjectionConfiguration();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment