[英]How to add custom headers on swashbuckl asp.net core web api
我在asp.net核心上創建了一個webapi,對於文檔,我使用了大方的swashbuckl。
我的API需要一些自定義標頭來驗證請求以及jwt-token
我需要這個自定義標題
orgid:fe5mp0 brnid:NY0023授權:Bearer
我設法添加了Authorization標頭,並且它可以正常工作,但是找不到如何添加這些自定義標頭。
官方解釋在這里
https://github.com/domaindrivendev/Swashbuckle/issues/501#issuecomment-143254123
public class AddRequiredHeaderParameter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters == null)
operation.parameters = new List<Parameter>();
operation.parameters.Add(new Parameter
{
name = "Foo-Header",
@in = "header",
type = "string",
required = true
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.