我想添加自定义标头来招摇。我正在使用swagger 5.0.0-rc4的asp.net core 3.0。 我的中间件会收到类似于“密钥:价值”的东西。
public class MyHeaderFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<OpenApiParameter>();
operation.Parameters.Add(new OpenApiParameter
{
Name = "Authorization",
In = ParameterLocation.Header,
Description = "Authenticate API Key",
Required = false,
Schema = new OpenApiSchema
{
Type = "String",
Default = new OpenApiString("Bearer")
}
});
}
}
答案 0 :(得分:0)