complete controllers
This commit is contained in:
@@ -25,7 +25,7 @@ public class Program
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
//options.OperationFilter<SwaggerHttpHeaderOperation>();
|
||||
options.OperationFilter<SwaggerHttpHeaderOperation>();
|
||||
|
||||
var scheme = new OpenApiSecurityScheme
|
||||
{
|
||||
@@ -53,7 +53,7 @@ public class Program
|
||||
Description = "<p>花事记录,贴心的帮您记录花园中的点点滴滴。</p><p><b>API 文档</b></p>"
|
||||
});
|
||||
|
||||
options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Server.xml"));
|
||||
options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Server.xml"), true);
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<FlowerDatabase>(options => options.UseSqlite("DataSource=flower.db;Cache=Shared"));
|
||||
@@ -84,23 +84,26 @@ public class SwaggerHttpHeaderOperation : IOperationFilter
|
||||
/// <inheritdoc/>
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
var required = context.ApiDescription.RelativePath switch
|
||||
switch (context.ApiDescription.RelativePath)
|
||||
{
|
||||
"user/update" or
|
||||
"user/profile" or
|
||||
"user/logout" => true,
|
||||
_ => false
|
||||
};
|
||||
if (required)
|
||||
{
|
||||
operation.Parameters.Add(new OpenApiParameter
|
||||
{
|
||||
Name = "Authorization",
|
||||
Description = "授权 Token",
|
||||
In = ParameterLocation.Header,
|
||||
Required = true,
|
||||
Schema = new OpenApiSchema { Type = "string" }
|
||||
});
|
||||
case "api/user/auth":
|
||||
operation.Parameters.Add(new OpenApiParameter
|
||||
{
|
||||
Name = "X-ClientAgent",
|
||||
Description = "客户端代理",
|
||||
In = ParameterLocation.Header,
|
||||
Required = false,
|
||||
Schema = new OpenApiSchema { Type = "string" }
|
||||
});
|
||||
operation.Parameters.Add(new OpenApiParameter
|
||||
{
|
||||
Name = "X-DeviceId",
|
||||
Description = "设备 id",
|
||||
In = ParameterLocation.Header,
|
||||
Required = false,
|
||||
Schema = new OpenApiSchema { Type = "string" }
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user